我正在开发一个 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;
}
}
提前致谢!