2010-07-23 113 views
9

我只是好奇我怎麼能附加一些不同的任務到UIAlertView的otherButtonTitle。 取消按鈕會自動將您帶出應用程序,但如果我想使用otherButtonTitle附加不同的任務,我該怎麼辦?UIAlertView其他按鈕標題

感謝,

回答

22

UIAlertView中代表 「didDismissWithButtonIndex」 得稱爲U點擊任意按鈕,每一次。

試試這個:

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Message" 
               message:messageString 
               delegate:self 
             cancelButtonTitle:@"Back" 
             otherButtonTitles:@"Reply",@"Delete",nil]; 
[alert show]; 
[alert release]; 


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 1) 
    { 
    NSLog(@"Reply"); 
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Reply " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [myalert show]; 
    [myalert release]; 
    } 

    if (buttonIndex == 2) 
    { 
    NSLog(@"Delete"); 
    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:@"Button Clicked" message:@"U clicked Delete " delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [myalert show]; 
    [myalert release]; 
    } 
} 
+0

它不是什麼洞,當我點擊任何一個按鈕。 – Ashutosh 2010-07-23 05:44:29

+0

找到更新的代碼 – iPhoneDev 2010-07-23 06:34:06

+0

正確的答案。提示:不要將'didDismissWithButtonIndex'(在UIAlertView離開屏幕層次結構後調用*)與'clickedButtonAtIndex'(在UIAlertView仍在屏幕上時調用,仍然是屏幕視圖層次結構的一部分,並且顯着影響屏幕視圖層次結構)混淆。我在其他的StackOverflow答案和網絡上的其他地方發現了這種混淆。 – 2014-05-06 02:18:39