Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbalanced calls to begin/end appearance transitions in UISplitViewController

My UISplitViewController basically works like a charm except that there is an annoying error message displayed when transitioning the first time (first time only!) from the master table view to the detail view.

Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x160015600>.

Both the master and the detail view controller are embedded in a UINavigationController. However, the error only occurs when setting the following (which is necessary for logic behavior on the iPhone):

class MySplitViewController: UISplitViewController, UISplitViewControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
    }

    func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
        return true
    }
}

It would be great if anyone could provide a solution to this issue, thanks in advance.

BTW: the split view controller was set up in the storyboard

Presenting the detail view controller is done in the tableView:didSelectRowAtIndexPath: method like this:

if let detailViewController = delegate as? DetailViewController {
    detailViewController.navigationItem.leftItemsSupplementBackButton = true
    detailViewController.navigationItem.leftBarButtonItem = splitViewController!.displayModeButtonItem()
    splitViewController!.showDetailViewController(detailViewController.navigationController!, sender: self)
}
like image 335
borchero Avatar asked Dec 27 '15 18:12

borchero


1 Answers

Most probably, your first transition from master (UITableView in UIViewController?) to detail (UIViewController) view in your UISplitViewController starts before the active/current view has finished displaying itself.

A possible reason for this is that you are possibly trying to present the first "instance" of the detail view in the viewDidLoad() method of you master UIViewController? In such a case, you app might try to present the detail view prior to master view finished appearing. Note the difference here between view did load a view and view did appear:

override func viewDidLoad()

Description:

Called after the controller's view is loaded into memory.

This method is called after the view controller has loaded its view hierarchy into memory.


override func viewDidAppear(animated: Bool)

Description:

Notifies the view controller that its view was added to a view hierarchy. You can override this method to perform additional tasks associated with presenting the view.

Now, as you question doesn't show how you load your initial detail view, the following advice is maybe already heeded by yourself, but anyway: if your detail view is presented from the viewDidLoad(), try to move this to the viewDidAppear() method:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(true)

    // present/load detail view here instead
}
like image 193
dfrib Avatar answered Sep 24 '22 02:09

dfrib