按UIAlert按钮后如何导航视图控制器

时间:2016-01-13 06:50:11

标签: ios objective-c

我有两个屏幕。从第一个屏幕到下一个屏幕,我在故事板中连接了push segue。现在在我的第二个屏幕中,一个警报将显示ok按钮。按下确定按钮后,我需要转到我的第一个屏幕

这是我的代码:

- (void)signup:(NSDictionary *)params {
    if (error)
    {
        [PCUtilities showAlertWithTitle:@"Oops" message:error.localizedDescription cancelButtonTitle:@"ok"];
    }
}

在一个方法中我有UIAlert

以下代码我尝试了但没有工作!!

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"ok"])
    {
        [self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"AppMainNavController"] animated:YES];
    }
}

AppMainNavController =是我的导航控制器故事板ID

3 个答案:

答案 0 :(得分:1)

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if  (buttonIndex==0)
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

答案 1 :(得分:0)

只需弹出到上一个视图控制器,如下所示。它将弹出到你已经推出的上一个视图控制器。

        - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
        {
            NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
            if([title isEqualToString:@"ok"])
            {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }

答案 2 :(得分:0)

如果应用程序有多种语言,则使用按钮索引而不是按钮标题会很困难。如果您正在使用push segue然后只关闭当前视图控制器,它将自动进入上一页天气有Push segue或模态segue。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
相关问题