单击UIAlertView按钮时更改视图

时间:2013-02-14 21:03:04

标签: uitableview ios6 hyperlink uialertview

我有一个以TableView开头的测验程序,然后在选择测验时移动到第二个View。在第二个视图中,顶部有一个导航栏,后面有一个按钮,可以将您带回到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];
    }
}

}

1 个答案:

答案 0 :(得分:2)

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

[self.navigationController popToRootViewControllerAnimated:YES]

此信息由Apple IOS Developer Library here提供。

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];        
        }
    }
}