gar*_*hdn 2 iphone objective-c uialertview pushviewcontroller ios
我正在尝试根据用户的选择更改视图控制器UIAlertView.我是客观的新手,遇到了麻烦.
当用户按下"我已完成"时,我希望应用程序导航回上一个视图控制器.当用户按下"记分板"时,我希望应用程序导航到下一个视图控制器.
UIAlertView *jigsawCompleteAlert = [[UIAlertView alloc] //show alert box with option to play or exit
initWithTitle: @"Congratulations!"
message:completedMessage
delegate:self
cancelButtonTitle:@"I'm done"
otherButtonTitles:@"Play again", @"Scoreboard",nil];
[jigsawCompleteAlert show];
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Cancel Tapped.");
[self.navigationController popViewControllerAnimated:YES];
}
else if (buttonIndex == 1) {
NSLog(@"GO tapped.");
startDate = [NSDate date];
// Create the stop watch timer that fires every 10 ms
stopWatchTimer = [NSTimer
scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
} else if (buttonIndex == 2) {
NSLog(@"Scoreboard tapped.");
}
}
Run Code Online (Sandbox Code Playgroud)
popView部分正在运行,应用程序导航回一个视图控制器.我不知道如何让应用程序向前移动一个视图控制器.我知道这与此有关,pushViewController但我只看到了相当古老而矛盾的文章,详细说明了如何做到这一点.
谢谢,我对此表示感谢.
您需要创建新的UIViewController,然后将其推送到堆栈,如下所示:
else if (buttonIndex == 2) {
NSLog(@"Scoreboard tapped.");
MoreDetailViewController *ctrl = [[MoreDetailViewController alloc] initWithNibName:@"MoreDetailViewController" bundle:nil];
[self.navigationController pushViewController:ctrl animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用StoryBoard,则在storyboard文件(Attribute Inspector)中为您的UIViewController提供标识符.

将此代码放入处理程序:
MoreDetailViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MoreDetailViewController"];
[self.navigationController pushViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)