Keep getting “Unbalanced calls to begin/end appearance transitions for <ViewController>” error

十年热恋 提交于 2019-11-28 09:00:53
user3117509

I found the answer this morning in another stackoverflow question. The answer can be found here.

When I had originally setup the Push Segue, I clicked on and dragged from a button, and was also calling the performSegueWIthIdentifier method inside that button's IBAction method implementation. This was causing 2 identical push segues to be executed on the button press. I just left my method call in the IBAction, deleted the old push segue, and created a new push segue only this time I clicked on and dragged from the entire View Controller instead of it's button.

I solved this issue by wrapping in this.

dispatch_async(dispatch_get_main_queue()) {
    //call your performSegueWithIdentifier in here
}

In my case it was a subclass of UITabBarController with an overloaded setSelectedIndex: method that does the transition with an animation. I found that the following needs to be called before the animation start:

[sourceVC viewWillDisappear:YES];
[destinationVC viewWillAppear:YES];

And the following in the completion block:

if (finished) {
    [sourceVC viewDidDisappear:YES];
    [destinationVC viewDidAppear:YES];
    [super setSelectedIndex:selectedIndex];
}

The problem might still occur if multiple selectedIndex changes happen before animations end.

In my case this warning was caused by calling popToRootViewController of UINavigationController while modal view was displayed. When i moved popToRootViewController after modal view dismissed, warning stop to appear.

Reason For Error : This message get displayed if you are pushing/presenting another View controller from viewWillAppear,loadView,init or viewDidLoad method of current View Controller

Solution : Move your pushing/presenting code to viewDidAppear method will solve the issue

The reason is : in viewDidLoad not all of the fancy animations have already been finished, whereas in viewDidAppear everything's done.

I worked it and it is good for me Reason For Error : This message get displayed if you are pushing/presenting another View controller from TabBarController, Solution : please set viewController.modalPresentationStyle = .overCurrentContext, then present viewController topViewController.present(vc, animated: true, completion: nil)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!