2

我有一个以 TableView 开头的测验程序,然后在选择测验时移动到第二个视图。在第二个视图中,顶部有一个导航栏,带有一个返回按钮,可将您带回 tableView。当用户单击 UIAlertView 上的按钮时,我想完成相同的操作,该按钮在每个测验结束时显示他们的最终分数。任何人都可以帮我解决这个问题,或者指导我学习教程吗?这是我的第一个多视图应用程序。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if (alertView.tag == 5) {
    if ([buttonTitle isEqualToString:@"Main Menu"]) {
        KHQuizViewController *vc = [[KHQuizViewController alloc] initWithNibName:@"KHViewController" bundle:nil];

        [self.navigationController pushViewController:vc animated:YES];
        [vc release];
    }
}

}

4

1 回答 1

2

不要尝试推送主菜单的新实例,只需使用以下行弹回根视图:

[self.navigationController popToRootViewControllerAnimated:YES]

此信息由Apple IOS 开发人员库在此处提供。

在您的alertView选择器的上下文中:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
    if (alertView.tag == 5) {
        if ([buttonTitle isEqualToString:@"Main Menu"]) {
            [self.navigationController popToRootViewControllerAnimated:YES];        
        }
    }
}
于 2013-02-14T22:29:52.877 回答