2014-06-24 40 views
-2

我想看看客戶端已被推警報視圖按鈕什麼選擇,雖然記錄不會似乎工作哪個按鈕被按下的iOS AlertView觸發

-(IBAction)flattenBtn:(id)sender 
{ 
    UIAlertView* flatView = [[UIAlertView alloc] initWithTitle:@"Flatten Image" 
                 message:@"Are you sure you want to flatten your image?" delegate:self 
               cancelButtonTitle:nil 
               otherButtonTitles:@"Yes",@"No",nil]; 
    [flatView show]; 
    [flatView release]; 
} 


- (void)flatView:(UIAlertView *)flatView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     NSLog(@"YES"); 
    } 
    else if (buttonIndex == 1) 
    { 
     NSLog(@"NO"); 
    } 
} 

回答

1

使用這樣試試吧:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 
    if([title isEqualToString:@"Yes"]) 
    { 
     //your code if YES pressed; 
    } 
    else 
    { 
     //your code if NO pressed; 
    } 
} 
+0

先生,用戶把錯誤的alertview的委託方法,不與名稱發出。方法不會被調用。 –

+0

哦。匆匆趕過來。您需要使用'alertView'而不是'flatView' Paul。這將釘住這一點。 –