4thSpace 4thSpace - 4 months ago 18
iOS Question

How to dismass modal viewcontroller without navigationcontroller?

I have two

UIViewControllers
. There is no embedded navigationcontroller. They are connected by a segue, which is a "Present Modally".

I have a button on scene2. When it is clicked, I call this code:

self.navigationController?.popViewControllerAnimated(true)


I can see the code is hit but nothing happens. What am I doing wrong?

Answer

Whay you are doing wrong is that you are pushing a view controller to a non existing navigation controller.

Basically when you say self.navigationController? that returns nil because there is no navigation controller. So the pop function doesn't get called.

In your case you have two options:

What you have to do is call self.dismissViewControllerAnimated(true, completion: nil).

Comments