在AlertView中单击“登录”按钮后,尝试转换到新的UIView

时间:2012-05-20 06:38:53

标签: ios alertview

我搜索了一些方法,一旦点击警报视图上的按钮,我就可以转到新页面。我必须使用prepareForSegue方法吗?或者有更简单的方法吗?

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

    if(buttonIndex ==0){
        //code goes here
    }

    if(buttonIndex ==1){
        NSString *username = [[alertView textFieldAtIndex:0] text];
        NSString *password = [[alertView textFieldAtIndex:1] text];
        NSLog(@"Username:%@",username);
        NSLog(@"Password:%@",password);

        //Check if username and password tally if tally move on to Menu page
        MainPageViewController *anotherController = [[MainPageViewController alloc] initWithNibName:@"AnotherView" bundle:nil];

        [self.navigationController pushViewController:anotherController animated:YES];
    }
}

1 个答案:

答案 0 :(得分:0)

您必须使用alertview委托方法 - alertView:clickedButtonAtIndex:来了解单击了哪个按钮,您可以对其执行后续操作。