尝试使用AlertView推送到另一个视图控制器

时间:2012-10-18 19:24:10

标签: ios alertview

我在编写AlertView以推送到新的ViewController时遇到了麻烦。我已经遵循了几个教程,仍然无法使其正常运行。任何帮助将不胜感激。

- (IBAction)web:(id)sender {
    UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"You are now entering a website outside of the Company App: Any links or references to other Internet sites (hyperlinks) are provided by Company merely as a convenience to users of this App." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Proceed", nil];

        [testAlert show];
        [testAlert release];

}

-(void)web:(UIAlertView *)web clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (buttonIndex == 0) {
    }
    else if (buttonIndex == 1) {

    JBWebViewController *jbweb = [[JBWebViewController alloc] initWithNibName:@"JBWebViewController" bundle:nil];
        [self.navigationController pushViewController:jbweb animated:YES];
    }
}

1 个答案:

答案 0 :(得分:1)

您应该使用UIAlertView委托

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

不是

-(void)web:(UIAlertView *)web clickedButtonAtIndex:(NSInteger)buttonIndex

并检查self.navigationController不是nil