我想打开一个登录屏幕,我已经尝试过编程方式和 segue。我见过类似的问题,但它并没有为我解决。
这是我的两个版本的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (![[API sharedInstance] isAuthorized]) {
NSLog(@"I should Open login screen");
[self performSegueWithIdentifier:@"ShowLogin" sender:nil];
}
}
或者
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (![[API sharedInstance] isAuthorized]) {
NSLog(@"I should Open login screen");
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginScreen *vc = [sb instantiateViewControllerWithIdentifier:@"LoginScreen"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
}
}
segue 是模态风格。
在这两种情况下,都会打印 NSLog,然后我看到一个警告:
Warning: Attempt to present <LoginScreen: 0x1e5bd010> on <PhotoScreen: 0x1e5b82e0> whose view is not in the window hierarchy!
并且新视图没有打开。
有什么提示吗?