【发布时间】:2016-02-07 10:48:59
【问题描述】:
我是这个领域的新手。我正在开发一个应用程序,用户可以在其中从应用程序内的任何页面注销。
我在注销过程中使用这种方法。 (引用自What is the perfect way to make a logout from IOS app?)
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:nil forKey:@"UserId"];
[defaults synchronize];
//redirect to login view
NewClassMoonAppDelegate * appsDelegate =[[UIApplication sharedApplication] delegate];
LoginViewController *second = [[LoginViewController alloc]initWithNibName:nil bundle:nil];
[appsDelegate.window setRootViewController:nil];
[appsDelegate.window setRootViewController:login];
}
}
我的问题是如何在执行注销之前关闭所有打开的 ViewController?当我实现上述方法时,我单击注销按钮的页面在后台保持打开状态。任何人都可以帮助我解决同样的问题。提前致谢。
【问题讨论】:
-
您应该在注销成功后执行“关闭”堆栈中的所有 VC。只需致电
[self.navigationController popToRootViewControllerAnimated:YES];。这将弹出导航堆栈中的所有现有 VC,并将您带回您的根 Vc -
视图控制器留在后台?你是什么意思。它仍然可见吗?
-
谢谢@NSNoob.. 这个应用程序没有使用导航控制器。有没有其他办法..??
-
是的@MarkHim,当我在模拟器上运行它时,该页面仍然可见。
-
@luckyShubhra 你是在模态地表达你的观点吗?
标签: ios