弹出以模态方式呈现的UINavigationController

时间:2012-09-10 02:34:27

标签: objective-c ios5 uinavigationcontroller modal-dialog modalviewcontroller

我正在开发一个首先向用户提供登录窗口的iOS 5应用程序。成功登录后,将执行Modal Segue,其中包含UINavigationController,其中包含大量实际应用程序。从现在开始,很多事情都会发生,但我感兴趣的是当用户决定退出时。

我想返回第一个视图,即登录窗口,但我似乎无法弹出导航控制器并返回第一个视图。

作为可视化:

                                             (NavigationController)
[UserLoginViewController] --modal segue-> [UserMenuTableViewController] --push segue--> [otherviews, etc]
     ^                                                  |
     |                                             modal segue
     |                                                  |
     |                                                  v
     ^                                    [UserDashBoardViewController]
     |                                                  |
     |                                           (logout pressed)
     |                                                  |
      -<---------------pop back to login--------------<-

我已尝试委托,通知初始登录视图,是时候关闭以模态方式呈现的导航控制器,但是我收到错误:

2012-09-10 11:13:05.749 KITxWebMobileJSONv4[1138:f803] attempt to dismiss modal view controller whose view does not currently appear. self = <UINavigationController: 0x68c6150> modalViewController = <UserDashboardViewController: 0x68d9fb0>
2012-09-10 11:13:05.749 KITxWebMobileJSONv4[1138:f803] attempt to dismiss modal view controller whose view does not currently appear. self = <UserLoginViewController: 0x688ffa0> modalViewController = <UINavigationController: 0x68c6150>

登录视图委派如下所示:

// This method is called from the UserMenuTableViewController, when it's time to log out:
- (void)userMenuTableViewController:(UserMenuTableViewController *)sender
                          loggedOut:(BOOL)didLogOut
{
    if (didLogOut) {
        /* delete user info and take care of data on backend:
         * ...
         */

        // pop navigation controller, presenting the initial Login View:
        [self dismissModalViewControllerAnimated:YES];  // THIS LINE FIRES AND GETS THE ERROR ABOVE
    }
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"Login Success"]) {  // successful login:

        // set (UINavigationController *)self.nav to the segue destination (for a handle, if needed):
        self.nav = (UINavigationController *)segue.destinationViewController;

        // grab the user menu and set self to be it's delegate:
        UserMenuTableViewController *userMenu = [self.nav.viewControllers lastObject];
        userMenu.delegate = self;
    }
}

提前致谢!

2 个答案:

答案 0 :(得分:1)

在调用NavigationController后出现的viewController中,调用此

[self dismissViewControllerAnimated:YES completion:nil];

您要弹出您的navigationController。这对我有用。

答案 1 :(得分:1)

有点太晚但你可以使用展开segues来做到这一点,它会相应地解开。