Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar button item missing after segue style "Replace"

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.

like image 205
Vinny Avatar asked Jan 16 '13 14:01

Vinny


People also ask

How do I add a button to my navigation bar?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.

How to remove a presented view controller?

To dismiss a modally presented view controller, call the view controller's dismiss(animated:completion:) method.


1 Answers

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)
like image 120
FormigaNinja Avatar answered Oct 31 '22 06:10

FormigaNinja