Unbalanced calls to begin/end appearance transitions for

后端 未结 22 1857
长情又很酷
长情又很酷 2020-11-28 19:23

I read SO about another user encountering similar error, but this error is in different case.

I received this message when I added a View Controller initially:

相关标签:
22条回答
  • 2020-11-28 20:16

    Swift 5

     func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    
    
    //Delete or comment the below lines on your SceneDelegate.
    
    //        guard let windowScene = (scene as? UIWindowScene) else { return }
    //        window?.windowScene = windowScene
    //        window?.makeKeyAndVisible()
    
            let viewController = ListVC()
            let navViewController = UINavigationController(rootViewController: viewController)
            window?.rootViewController = navViewController
    
        }
    
    0 讨论(0)
  • 2020-11-28 20:17

    I fixed this error by changing animated from YES to NO.

    From:

    [tabBarController presentModalViewController:viewController animated:YES];
    

    To:

    [tabBarController presentModalViewController:viewController animated:NO];
    
    0 讨论(0)
  • 2020-11-28 20:17

    Another solution for many cases is to make sure that the transition between UIViewControllers happens after the not-suitable (like during initialization) procedure finishes, by doing:

    __weak MyViewController *weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        [weakSelf presentViewController:vc animated:YES];
    });
    

    This is general for also pushViewController:animated:, etc.

    0 讨论(0)
  • 2020-11-28 20:19

    Without seeing more of the surrounding code I can't give a definite answer, but I have two theories.

    1. You're not using UIViewController's designated initializer initWithNibName:bundle:. Try using it instead of just init.

    2. Also, self may be one of the tab bar controller's view controllers. Always present view controllers from the topmost view controller, which means in this case ask the tab bar controller to present the overlay view controller on behalf of the view controller. You can still keep any callback delegates to the real view controller, but you must have the tab bar controller present and dismiss.

    0 讨论(0)
提交回复
热议问题