我想弄清楚如何从注销按钮显示登录(模态视图 Controller )并从登录下方自动关闭设置(模态视图 Controller )。您可能会看到 Storyboard布局:
http://cl.ly/2B3h0T130S1K1026201N
我试图将此代码添加到 SettingsViewController.m 的注销方法中
- (IBAction)logoutAccount {
[self dismissModalViewControllerAnimated:YES];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
}
问题是当我点击注销时它强制我的应用程序卡住。有人知道它有什么问题吗?任何建议表示赞赏。
最佳答案
用户再次登录后,你希望应用在什么位置?假设您希望应用位于设置按钮所在的 View Controller 中(从 Storyboard 中看起来就是这样)。
然后那个vc(导航 Controller 中的根vc)可以这样做:
- (void)viewDidAppear:(BOOL)animated {
if (/*login is needed*/) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:YES];
} else {
// normal view did appear logic
}
}
注销按钮现在可以做到这一点:
- (IBAction)logoutButtonPressed:(id)sender {
[self.navigationController popToRootViewControllerAnimated:NO];
}
关于iphone - 如何显示登录和关闭设置 - Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10302992/