How to correctly close modal presented controller


November 2018


940 time


I am opening a navigationController using either directly navigation segue in storyboard or called segue from code, but still created on storyboard.


 self.performSegue(withIdentifier: "addNew", sender: nil)

Which then with modal transition opens a navigationController. NC then has a few view controllers on which all have close button on them and when I click on it it closes NC using:

self.navigationController?.dismiss(animated: true, completion: nil)

But afterwards when I switch between different ViewControllers on TabbarController or open some other view with push view I get:

Unbalanced calls to begin/end appearance transitions for

And also viewWillAppear on opened view isn't called. So can anyone tell me if I'm closing the NC correctly or is there some other way to prevent the error.

EDIT1: changed the closing call from controller.navigationController?.dismiss(animated: true, completion: nil)

to self.navigationController?.dismiss(animated: true, completion: nil) just to make the question easier.

Also tired:

self.dismiss(animated: true, completion:nil)

EDIT2: Is it maybe bad to open a NC from VC that is on NC that is on UITabbarController or is just simply already bad to have NavigationControllers as tabs on TabbarController?

1 answers


Вы, возможно, потребуется, чтобы закрыть контроллер со стороны этого контроллера:

// place this to the target controller, which handles you that modal view
self.dismiss(animated: true) {

или же

self.dismiss(animated: true, completion:nil)