弹出到下一个视图控制器iOS

时间:2015-06-26 06:00:01

标签: ios objective-c

我有5-6个视图控制器。我试图弹出特定的视图控制器。就像我有第一个视图名称"访客"第二个视图名称"供应商"第三个视图名称"地址"。现在我在"地址"我希望进入"访客"视图。但这不会正确发生。任何人都可以帮助我。下面是我用来从视图中弹出的给定代码..

- (void)addButtonAction
{
    if([selectVisitor.text isEqualToString:[NSString stringWithFormat:@"Guest"]])
    {
        NSLog(@"NISha");
        for (UIViewController *Controller in self.navigationController.viewControllers)
        {
            if ([Controller isKindOfClass:[GuestView class]])
            {
                [self.navigationController popToViewController:Controller animated:YES];
                break;
            }
        }
    }
}

2 个答案:

答案 0 :(得分:0)

试试这个

- (void)addButtonAction {

    if([selectVisitor.text isEqualToString:[NSString stringWithFormat:@"Guest"]])
    {
        BOOL flag = FALSE;
        for (UIViewController *Controller in self.navigationController.viewControllers)
        {
            if ([Controller isKindOfClass:[GuestView class]])
            {
                [self.navigationController popToViewController:Controller animated:YES];
                flag = TRUE;
                break;
            }
        }
    }
    if(!flag) {
        GuestView *controllerObject = [[GuestView alloc] initWithNibName:@"GuestViewNibName" bundle:nil];
        [self.navigationController pushViewController:controllerObject animated:YES];
    }

}

答案 1 :(得分:0)

试试这个

[self.navigationController popToRootViewControllerAnimated:YES];