在我的非root VC类中,我有以下doLogout
方法:
- (void)doLogout
{
SDPAppDelegate *app = [self getAppDelegate];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[SSKeychain deletePasswordForService:app.productName account:[defaults stringForKey:@"EmailAddress"]];
[defaults removeObjectForKey:@"LoggedIn"];
[defaults removeObjectForKey:@"EmailAddress"];
[defaults removeObjectForKey:@"Password"];
[defaults synchronize];
[self setToolbarItems:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
}
然后在我的根VC中,在viewWillAppear
中,我有:
- (void)viewWillAppear:(BOOL)animated
{
if (![self isLoggedIn]) {
NSLog(@"Should perform segue bro");
[self performSegueWithIdentifier:@"loginSegue" sender:self];
}
}
}
这大部分都有效,用户注销并且堆栈已正确恢复到根控制器,并执行NSLog()
调用,但不执行segue。这是为什么以及可以做些什么?如果用户注销,我想显示登录VC(弹出到根VC)。
答案 0 :(得分:1)
尝试在ViewDidAppear中添加此代码,而不是viewWillAppear
- (void)viewDidAppear:(BOOL)animated
{
if (![self isLoggedIn]) {
NSLog(@"Should perform segue bro");
[self performSegueWithIdentifier:@"loginSegue" sender:self];
}
}
}