2012-08-14 19 views
0

我一直在尋找幾個小時,還沒有找到任何答案,所以我會非常感謝您的幫助!iOS Dev:通過按下Alert中的按鈕?

我正在設計一個應用程序,並且需要在按下警報中的按鈕時繼續使用不同的視圖控制器。我已經設置了警報,但只需要代碼繼續到新視圖。

回答

3

試試這個。首先創建alertview。

UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Message" message:@"Open New controller?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes",nil]; 
[alertView show]; 
[alertView release]; 

落實AlertView委託方法

#pragma mark AlertView Delegate 
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex != alertView.cancelButtonIndex) 
    { 
     Viewcontroller *vc = [[UIViewcontroller alloc] initWithNib:@"Viewcontroller"]; 
     [self presentModalViewController:vc]; 
     [vc release]; 
    } 
} 
0

執行UIAlertViewDelegate,然後您將得到一個回調,當警報被解除時按下哪個按鈕。在那裏只需撥打performSegueWithIdentifier即可。

UIAlertViewDelegate protocol reference

1

更多細節落實UIAlertViewDelegate並添加方法alertView:clickedButtonAtIndex:。點擊右鍵後,調用該方法以繼續進入新視圖。