4thSpace
4thSpace

Reputation: 44312

How to pop UIViewController when no NavigationController?

My initial scene has a navigation controller embedded. This scene links to a UITableViewController scene. The tableview scene doesn't know anything about the navigation controller.

In the tableview scene, I've added a navigation bar and left button called back. How do I get back to the previous scene?

I have the following action associated with the back button:

self.navigationController?.popViewControllerAnimated(true)

But it doesn't do anything because self.navigationController is nil.

Upvotes: 1

Views: 56

Answers (1)

NRitH
NRitH

Reputation: 13893

If your navigationController is nil, then your scene must have been displayed modally, not pushed onto a nav controller. Instead of popping it, you have to call dismissViewController on it.

A better approach than using a left button item to navigate is to use the nav bar's built-in functionality by setting a custom backIndicatorImage and mask.

Upvotes: 2

Related Questions