2

我正在开发一个 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;
    }
}

提前致谢!

4

2 回答 2

1

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

[self dismissViewControllerAnimated:YES completion:nil];

你想在哪里弹出你的navigationController。这对我有用。

于 2012-09-10T03:52:51.890 回答
1

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

于 2017-01-24T03:32:32.077 回答