ios - 警告 : Attempt to present on whose view is not in the window hierarchy

标签 ios uiviewcontroller

我知道有一百万个这样的问题,但解决方案对我不起作用。

每个人都在说,你需要推送到 ViewDidAppear 中的下一个 View Controller ,我就是这样做的,但仍然不起作用。

我正在使用 PARSE,并且根据用户登录时的说明 - 我想跳过登录屏幕并打开下一个。

这是我在 LoginViewController 中的代码。

- (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];
}

我看到了日志消息,但另一个 View Controller 没有打开 - 我仍然停留在登录 View Controller 中。

最佳答案

您在 viewDidAppear: 中呈现 View Controller ,但您发布的代码在 viewWillAppear: 中呈现 View Controller 。

View Controller 尚未呈现的 WILL 与 View Controller 已呈现的 DID 之间存在差异。

关于ios - 警告 : Attempt to present on whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26078198/

相关文章:

ios - 如何多次推送同一个 ViewController?

ios - 从照片应用程序中选择时将 UITabBar 重新创建为 UIToolbar

swift - 如何使用 Swift 循环遍历 UIViewController 中的 View 导出?

ios - 如何使用iOS版Google Drive SDK与多个用户共享文件?

iOS PayPal 与后端链式支付的集成

ios - 将 JSON 解析为 TableView 时出现 NSNull 长度错误

ios - 如何快速过滤字典并将结果输出到 CollectionViewController

ios - 更改当前日期

ios - ios viewcontroller 的背景图像不工作

ios - 将 UIView 设置为键盘高度