Storyboard loses navigation bar when segueing via tap gesture - ios

My app has two scenes: a UIViewController with a navigation bar at the top, and a UITableViewController. If I wire up a button in the first scene to segue to the table view, everything looks great. However, if I wire up a tap gesture in the first scene to segue to the table view, then the navigation bar doesn't display in the second scene in Xcode. When the app is run, the navigation bar appears as it should, but in the storyboard editor it is gone.
Is there something special that needs to be done to preserve the navigation bar when segueing from one scene to another using a tap gesture? To implement the tap gesture, I dragged it onto one of the elements in my storyboard, then control dragged from the "tap gesture recognizer" icon at the bottom of the scene to the scene I wanted it to segue to. Then selected "push" for the segue type.

I never noticed this before, but I do see the same thing. This seems like a bug to me, but maybe Apple has a reason for doing this. You can go to the "Simulated Metrics" for your controller, and set the "Top Bar" to be a navigation bar, which will allow you to set the title and add a bar button item if you want.

Related

Segue is not working in storyboard after creating navigation bar

Hi I created a single view project and i put a button in the scene that I embed in navigation bar with a bar button on the right to this scene and then I created the second screen which contain an image view, Then I dragged bar button to second scene using Crtl+Drag and choose show action for segue. which works fine.
Problem : Then I created third scene with some image view in it and I dragged the button from first scene with Crtl+Drag to the third scene and choose "show" for segue action.
but when I run the app only navigation bar segue works and the button do nothing.
UPDATE :
I found why this problem occurs, it's because of stack view constrains. when i put a button or image view in stack view and give it constrain it won't work. but why ?
any suggestion?
As per the discussion, your first problems were solved by setting UserInteractionEnabled to true on the UIImageView, and as for the buttons, it seems they were set up incorrectly the first time.

iOS navigation has no navigation item

In the current version of Xcode a few things seems to work a bit different.
I have a little problem working with a simple navigation. This is what I do:
I have a Storyboard with two scenes.
I connect the scenes with a segue of type "Show".
(In the past I did use "Push" but that is deprecated now.)
I select the first scene and choose "Embed in Navigation Controller.
Now both scenes will get a gray bar at the top but only the first scene will also get a Navigation Item.
Only for the first scene I am able to edit a title attribute and only for the first scene I am able to add a Bar Button.
Navigation itself works fine. The title of the first scene is the text of the Back-button in the second scene.
Why has the second scene no Navigation Item?
Is it because of the segue type?
Yeah, its a bug in Xcode from version 6. If you want Navigation Item in second view controller too, then there is a hack to get it.
Change the seque type from show to push. Now Navigation Item will appear in second VC too. You can again change the seque type from push to show, the Navigation Item will still present in second VC.
IB will automatically add UINavigationItem to root view controller of your UINavigationController.
To the rest of your controllers in navigation flow you need to add UINavigationItem manually from IB Object library.
What I do is to drag a navigation item from the list of controls to the top, gray bar on the second ViewController. Then you can drag other items such as bar buttons onto it, as well as being able to edit the title.

Custom segue causes navigation item to disappear

I'm using custom segues with no animation because I don't like the animation of the default segue. The problem is that in the storyboard, when I flip the segue style from Push to Custom, the view controller's navigation item disappears. Now, it seems that the navigation item still works even if the segue is set to Custom, but that means constantly flipping back and forth between Push and Custom when changes need to be made.
Is there any way to use a custom segue and still have IB access to the navigation item?
Yes, select the view controller and open the attributes inspector. Then change the "Top Bar" from "Inferred" to "Navigation Bar". That should keep the navigation bar displayed.

Using Xcode Storyboard to create Master-Detail views where the Detail view is Tab Bar to three different views

I'm trying to implementing master-detail scenes where the detail scene can be tabbed to show three different scenes. The example is a list of stories and for each story, I am interested to present an introduction, author info and reviews. So the scenes are as the following:
Master scene: a list of stories
When a story is selected:
Detail - Introduction scene (about the selected story)
Detail - Author scene (about the author)
Detail - Reviews scene (a list of reviews)
I attached the storyboard that I used to kind of achieve this:
https://docs.google.com/file/d/0B6I7Mlt7gqCBVTFZR2lsX0Q4MUk/edit?usp=sharing
I also attached the resultant scene on the iPhone simulator that showed the Detail - Author scene:
https://docs.google.com/file/d/0B6I7Mlt7gqCBQWhLTlNwWjZ2TG8/edit?pli=1
My problem is with there are 2 navigation bars presented in the detail - author scene: The top one with Stories back button, and the bottom one with Author label and B button. I want them to be collapsed into just one navigation bar. This means that when I click on a story from the Stories scene to transition to the detail author view, there will be only one navigation bar that has the Stories back button, the Author label, and the B button.
My question is: How can I collapse these two navigation bars together? Any advice would be greatly appreciated.
The problem is that you have a root navigation controller and you also have a navigation controller in each tab of the tab controller, then you show them both at the same time.
You could try a couple of things:
Hide the root nav controllers nav bar when the tab view is on display. This could be manual or by presenting modally. In either case you will need a done / back button to dismiss. The modal option could be done in the storyboard.
Add a delegate to the tab bar controller. Remove the nav controllers from each tab. When the tab changes, get the new view controller and set its navigationItem onto the root nav controllers nav bar.
Back button items are only shown when there is something to go back to. You can add left button items. You may be able to connect them to an unwind segue or you might need to add a method to each view controller which does:
[self.tabBarController.navigationController popViewControllerAnimated:YES];
I figured out one solution:
Objectives: When combining a Master-Detail scheme with the Detail part spreads to several scenes via tab bar controller using Push segue from Master to the tab bar scene, I want to: 1). retain the back button from the push segue, 2). set the navigation item on the tab bar scene to whichever detail scene that is visible, 3). set the right button on the detail scene. Another objective is to just use Storyboard to convey the GUI design and interaction flow, without getting into the code.
Problems: There were many problems with which controllers to use. (And one can play with the Xocde project that I uploaded here to see them.) One good solution is to use a navigation controller for each detail scene, which enables the bar button item to be added to the navigation bar on the detail scene (do not add a navigation bar to the detail scene yourself). Just from Storyboard, this worked fine, except that the navigation bar from the navigation scene would show up under the navigation bar from the tab bar scene, and the upper navigation bar wouldn't have the correct title or the correct button on it.
Solutions: The basic use of all the scenes as described in the original post is fine. For the programmatic changes part, create a view controller .h and .m for the detail scene. Then in the viewDidAppear method, retrieve the bar button that was added to the right side of the detail scene's navigation bar, and then assign it to the right bar button item on the tab bar scene's navigation bar.
The code snippet is as the follows - this is applicable to scenes that I described earlier:
UIBarButtonItem *detailButton = self.navigationItem.rightBarButtonItem;
self.parentViewController.parentViewController.navigationItem.rightBarButtonItem = detailButton;
On the Storyboard canvas, select the navigation scene, and make sure it's navigation bar is turned off.
One thing that I particularly liked abut this that the separation of the GUI design and flow are totally there.
Hope this helps.

storyboard uinavigationcontroller does not allow me to drag items in

I have an existing ios5/xcode 4.2 app, and I want a button to open a view that will display a list of items, and have a back button and an add new button.
I thought I could achieve this by adding a button to the main view controller, then dragging in to the storyboard a new UITableViewController, then embed a UINavigationController (editor->Embed In->Navigation Controller).
Then i right clicked on the button, dragged it to the navigation controller, and thought, ok this should work.
However, there is no back button, and xcode will not let me drag one in, nor will it allow me to drag in the button bar item "[+]" for the link to add new.
When I run the app, the list shows, of course I have no way to go back to the view controller with the button on it.
What am i doing wrong? - thanks.
(my question is similar to this
but for xcode 4.2)
Embed the main view controller, not the new one, in a UINavigationController. This should add a simulated UINavigationBar to the main view (if not, set one up under Simulated Metrics). At this point you should be able to drop in a UIBarButtonItem to the main view's simulated bar.
Next, draw a connection from your button to the new UITableViewController to set up a push segue. At runtime, the back button will appear in the bar automatically.
Make sure when you try and drag the items into your view controller that the storyboard is zoomed in. XCode won't let you add items if you are zoomed out.

Resources