Swift - create back button without navigation controller

I have an app with a toolbar, but I don't want the bar at the top to make more room for viewing. So I decided not to use the navigation controller. I would like to add a return button to the toolbar. How can i do this?

Adding a button is simple enough, and setting the action to execute the SegueWithIdentifier is fine, but what happens is that the previous view just loads again, rather than showing it as it is, like a real back button. So if I click the 10th row on the TableView and navigate to a new page when I click the Back button, it loads the view from the top again, instead of showing it as scroll down to the last one.

+3


source to share


1 answer


Even if you don't want to UINavigationBar

, you do want UINavigationController

in this case, because it manages the "back stack" exactly the way you want it. Just hide your navbar by setting its property navigationBarHidden

to true

(in storyboard or in viewDidLoad

root view controller function ).



You can then use it navigationController.popViewController(true)

as usual in response to a custom back button press.

+17


source







All Articles