iOS开发:通过在Alert中按下button来争论?
我一直在寻找几个小时,还没有find任何答案,所以我会很感激你的帮助!
我正在devise一个应用程序,当按下一个警报button时,需要继续到不同的视图控制器。 我已经设置了警报,但只需要代码继续到一个新的观点。
尝试这个。 先创build一个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]; } }
实现UIAlertViewDelegate
并添加方法alertView:clickedButtonAtIndex:
点击右键后,调用该方法进入新视图。
实现UIAlertViewDelegate
,然后你得到一个callback,当警报被解除时按下哪个button。 只需在那里调用performSegueWithIdentifier
。
有关UIAlertViewDelegate协议参考的更多详细信息