Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy

后端 未结 30 3106
一整个雨季
一整个雨季 2020-11-21 23:39

Just started using Xcode 4.5 and I got this error in the console:

Warning: Attempt to present < finishViewController: 0x1e56e0a0 > on < ViewCont

30条回答
  •  醉酒成梦
    2020-11-22 00:12

    If other solutions does not look good for some reason, you can still use this good old workaround of presenting with the delay of 0, like this:

    dispatch_after(0, dispatch_get_main_queue(), ^{
        finishViewController *finished = [self.storyboard instantiateViewControllerWithIdentifier:@"finishViewController"];
        [self presentViewController:finished animated:NO completion:NULL];    
    });
    

    While I've seen no documented guarantee that your VC would be on the view hierarchy on the time dispatch block is scheduled to execution, I've observed it would work just fine.

    Using delay of e.g. 0.2 sec is also an option. And the best thing - this way you don't need to mess with boolean variable in viewDidAppear:

提交回复
热议问题