I’m adapting one of the tutorials here and I have hooked up my tableview cell so that the accessory action goes to an edit screen, I have a + button in the navbar that segues to the same screen but it adds a record and I’ve also created a new segue so that when a user taps a row it goes to another screen. I embded a navbar controller into this new controller (Players), but I’m finding that I have no back button on my navbar controller. What did I do wrong?
I think I fixed this, well I did fix it in that it works. But I’m keen to know if this is the correct way??
I am enjoying learning iOS but there is just so much to learn framework wise. Far harder than than just changing languages, because for the most part languages all do the same things in a round about way.
Anyway, I digress.
I removed my second NavigationController to players and created a new “push” segue (Apparently I must use push here - don’t know why though) from the table cell. Now I have my back button working. I also adjusted my performSegue code to not cast the segue.destination to a UINavigationController as this doesn’t exist and the destination now should just be my playersViewController.
A navigation controller basically gives you a stack of view controllers. The common stack terminology is that you ‘push’ a new item on top, and you ‘pop’ off the top one when you’ve finished with it. Pressing the back button pops the stack (until it reaches its root view controller, at which point it stops).
If you push a second navigation controller onto the first, then the back button will belong to the second navigation controller and can only try to pop the second stack. You’d need to do something extra to dismiss the second navigation controller completely, and reveal the first stack underneath it.
@jonny: Yup, looks like your approach is correct! Basically, iOS provides the navigation controller to handle navigation between different views - but all views should be on the same navigation controller, as you figured out.
Once you have the entire hierarchy embedded in one Navigation Controller (choose the initial view and go to Editor → Embed In → Navigation Controller), as you also correctly figured out, you use segues to alternate between them.
The reason you must use Push (or, as it has been replaced with in XCode 7, Show) is that other segues do not embed the displayed view in the navigation hierarchy.