Unwind Segue from Modal/Popover resulting in Unbal

2019-06-16 18:21发布

I have the following setup:

Nav Controller -> VC1 -Push--> VC2 -PopOver or Modal Segue--> VC3.

VC3 is unwinding back to VC1.

When the Segue from VC2 to VC3 is PopOver and Modal, the unwind ends in a warning: Unbalanced calls to begin/end appearance transitions for UIViewController"

If the Segue from VC to VC is push, the warning is gone.

enter image description here Any idea how to get rid of the warning or why its even showing?

2条回答
Summer. ? 凉城
2楼-- · 2019-06-16 18:47

It's a bug. Ignore it (or, if you want to be a good citizen, file a bug report with Apple).

查看更多
Luminary・发光体
3楼-- · 2019-06-16 18:58

I was able to reproduce your problem and find a solution!

It would be great if the unwind logic would take care of this. Maybe it's a bug, maybe not. Either way, the solution is to make VC2 (The controller that has the popup) the target of the rewind, then wait for it to finish appearing before popping up the nav controller. That ensures the rewind (reverse popup) animation has enough time to finish before moving further back. Even with the animations off, it still has to wait or else you get the error.

Your code for VC2 should be as follows. (Swift)

class VC2: UIViewController {
    private var unwind = false
    @IBAction func unwindToVC1(segue:UIStoryboardSegue) {
        unwind = true
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        if unwind {
            self.navigationController?.popViewControllerAnimated(false)
        }
    }
}
查看更多
登录 后发表回答