我正在尝试制作一个警报视图,以便在选择“是”(AlertView中的一个按钮)后,用户将被引导到一个新的视图控制器,其中包含我通过Storyboard制作的按钮。我的IBAction代码如下:
- (IBAction)alertButton:(UIButton *)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome Back to SymTrack!" message:@"Did you have reoccuring symptoms?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alert show];
}
这是clickedButtonAtIndex的代码,它为我提供了没有按钮的空视图控制器:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [[UpdateViewController alloc] init];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
我还尝试过clickedButtonAtIndex的其他代码,但我得到了所有这些代码的NSException:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:@"UpdateViewController"];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
或
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1)
{
UpdateViewController *updateVC = [self.storyboard instantiateViewControllerWithIdentifier:@"UpdateViewController"];
UINavigationController *alertNC = [[UINavigationController alloc] initWithRootViewController:updateVC];
[self presentViewController:updateVC animated:YES completion:nil];
}
}
注意:所有这些代码都在视图控制器中,并且单击时会显示警报视图。
提前致谢!