球队,
我有两个故事板。一个用于身份验证,另一个用于我的应用程序仪表板。
对于Authentication Storyboard初始化屏幕是loginScreen。登录成功后我正在加载Dashboard Storyboard。对于仪表板故事板,初始屏幕是MainViewController。
在这里,我在DashboardStoryboard中实现了注销。所以现在我想切换回我的身份验证故事板。
这里回到登录界面。但我认为这不是正确的实施方式。如果有一种方法可以做得更好会更有帮助吗?
-(void)logout{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Authentication" bundle: nil];
LoginViewScreenController *loginViewScreenController = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewScreenController"];
[self.navigationController pushViewController: loginViewScreenController animated:NO];
}
非常感谢您的反馈。
使用segue
和Storyboard Reference
非常容易。请按照步骤和屏幕截图进行操作
步骤1)
Storyboard Reference
。第2步)
Storyboard reference.
步骤-3)
-(void)logout
{
UIViewController *aVCObj = [[UIApplication sharedApplication]delegate].window.rootViewController;
if ([aVCObj isKindOfClass:[UINavigationController class]]) {
UINavigationController *aNavController = (UINavigationController *)aVCObj;
[aNavController popToRootViewControllerAnimated:YES];
}
}
这是一个诀窍,通过使用true
设置密钥NsuserDefaults
,当用户登录时,否则false
并使用presentViewController
方法相应地启动时导航您的应用程序没有动画,因此用户将无法获得任何选项以返回上一个vc。
看看下面代码说明上面的句子:
if ([[[NSUserDefaults standardUserDefaults] valueForKey:@"isloggedIn"] isEqualToString:@"true"]) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"loginView"];
[self presentViewController:vc animated:NO completion:nil];
}else{ // when logout
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"logoutView"];
[self presentViewController:vc animated:NO completion:nil];
}
如果你需要在vc出现时应用一些效果,只需在presentViewController
方法之前看到这两行,请参阅:
[vc setModalPresentationStyle:UIModalPresentationCustom];
[vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
注意:用户注销时将密钥设置为false。