Ios 警告:试图显示其视图不在窗口层次结构中的对象
我知道像这样的问题有一百万个,但解决方案对我不起作用 每个人都在说,你需要推到ViewDidDisplay中的下一个视图控制器,这就是我所做的,但仍然不起作用 我正在使用PARSE,并且按照用户登录时的说明-我想跳过登录屏幕并打开下一个屏幕 这是我在LoginViewController中的代码Ios 警告:试图显示其视图不在窗口层次结构中的对象,ios,uiviewcontroller,Ios,Uiviewcontroller,我知道像这样的问题有一百万个,但解决方案对我不起作用 每个人都在说,你需要推到ViewDidDisplay中的下一个视图控制器,这就是我所做的,但仍然不起作用 我正在使用PARSE,并且按照用户登录时的说明-我想跳过登录屏幕并打开下一个屏幕 这是我在LoginViewController中的代码 - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // Check if user is
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Check if user is cached and linked to Facebook, if so, bypass login
if ([PFUser currentUser] && [PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) {
NSLog(@"Settings Screen should open automatically");
[self _presentUserSettingsSetupViewControllerAnimated:NO];
}
}
- (void)_presentUserSettingsSetupViewControllerAnimated:(BOOL)animated {
NSString * storyboardName = @"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UserSettingsSetupViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"UserSettingsSetup"];
[self presentViewController:vc animated:animated completion:nil];
}
我看到日志消息,但另一个视图控制器没有打开-我仍然停留在登录视图控制器中。您正在
视图中显示视图控制器显示:
但是您发布的代码正在视图中显示视图控制器将显示:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Check if user is cached and linked to Facebook, if so, bypass login
if ([PFUser currentUser] && [PFFacebookUtils isLinkedWithUser:[PFUser currentUser]]) {
NSLog(@"Settings Screen should open automatically");
[self _presentUserSettingsSetupViewControllerAnimated:NO];
}
}
- (void)_presentUserSettingsSetupViewControllerAnimated:(BOOL)animated {
NSString * storyboardName = @"Main_iPhone";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UserSettingsSetupViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"UserSettingsSetup"];
[self presentViewController:vc animated:animated completion:nil];
}
视图控制器尚未显示时的WILL与视图控制器显示时的DID之间存在差异。您说您在
ViewDidDisplay:
中显示视图控制器,但您发布的代码在ViewWillDisplay:
中显示视图控制器。在视图控制器尚未显示的情况下,WILL
与视图控制器显示的情况下,DID
之间存在差异。哦,我甚至没有注意到这一点。。。我的目光集中在这个词上。。。抱歉-将其作为答案以便接受。将转换为答案。