18
votes

The iPad app that I'm working on makes use of Storyboards and segues. I'm trying to display a different view controller when the user clicks on different cells in the master view. After referring to different tutorials, the steps that were taken were -

  • In the Storyboard, Master View Controller, created static cells for the table view and added 3 different rows (i.e. cell 1, cell 2, cell 3)
  • Added a View Controller, selected it and attached a Navigation Controller to it (Editor -> Embed In -> Navigation Controller)
  • From cell 1 in Master View, I did a ctrl-click on the Navigation Controller.
  • Chose Segue Style "Replace" and Destination "Detail Split"
  • In tableView:didSelectRowAtIndexPath, added [self performSegueWithIdentifier:@"NewViewController" sender:self] to do the transition.

The result that I see is the detail view gets replaced.

But the navigation bar does not have the bar button item Master.

So I'm unable to click the Master button which would show the table containing cells from where I can navigate to a different view.

I've already read many blogs and seen commentary which talk about replacing a segue for similar problems. However nobody seems to have faced this specific issue while using storyboards and segues.

From my understanding using segues should help me achieve what I want. From those who have tried this approach, any pointers in the right direction will be helpful.

1
@Jules This was my first question on SO. The questions i ask in future will be more clear i hope :) - Vinny
The link below has the problem nicely described and I was able to fully understand why the navigation bar item was missing while using storyboards.. Check out the answer by oneMhz <raywenderlich.com/forums/viewtopic.php?f=2&t=1546> - Vinny
Thats a very interesting link that you showed. I'll put it use soon. Thanks. - Vinny
Not that it matters much at this remove, @JulesMazur, but how on earth would JSFiddle help anyone demonstrate their iOS code? - Sixten Otto

1 Answers

1
votes

Try changing the Segue Style from Replace to Push. It should resolve your problem.

When you push a UIViewController on a UINavigationController, it will be added to a stack and you will be able to navigate back :

Your navigation controller stack before tapping "Detail":

Master

Your navigation controller after tapping detail and navigating a little more ...:

Master -> Detail (Navigation button is displayed) -> Some other details (Navigation button is displayed) -> And maybe some more (Navigation button is displayed)

When you call a new segue using Replace like you did, the Master will be replaced with Detail, and you will not be able to navigate back because Master was replaced and it's not on the stack anymore.

Your navigation controller stack before tapping "Detail":

Master

Your navigation controller after tapping detail using replace like you did:

Detail (no navigation button because master was replaced and we don't have nothing more on the stack)