When using Show instead of Push, which is deprecated, with UINavigationController, the VC being shown doesn't have navigationItem - ios

Alright, here is the deal.
I have a UINavigationController which has a root VC. From this root VC, you can show another VC, and from there, another, and from there, another.
The problem is that I'm running into what I think is a bug in Xcode.
In the below image, you see a button in my rootVC navigationItem that I use to segue with Show to display the second VC. You can clearly see the Navigation Bar, but when I try to drag a UIBarButtonItem into it, I can't and the reason is because if you look at the menu on the left, you'll see that there isn't a Navigation Item to drag the button into!
If I instead use the segue Push to display the second VC, I get a navigationItem... but apparently Push is deprecated.
How do I mitigate this?
Edit: I guess I can just drag in a UINavigationItem into it... but I really don't know if I should. Would there be an empty UINavigationItem underneath that that I just don't see in storyboard but is actually there?

The navigation item is not created automatically on the second view controller, you're right. Drag a new navigation item into the second viewcontroller's bar, and you should be good to go.

Related

Toolbar not visible

Can anyone tell me why, in the storyboard here below, when I arrive from the first tab the toolbar is visible, but when I arrive from the second tab is not visible anymore.
The first tab has a navigation controller as the root controller - the second does not.
You can select SearchVC in your storyboard and then use the Editor - Embed In - Navigation Controller menu option to add a navigation controller. That might not be how you want your UI. But that would achieve what you want visually ...
Update:
Based on discussions with the OP, the issue was that SearchVC was adding EditorVC as a child view controller and then EditorVC in turn would add ReadVC to the navigation stack.
EditorVC, as it appears above, is embedded within a UINavigationController. I suggested that OP remove that UINavigationController instance and then push EditorVC on to SearchVC's navigation controller and then later when ReadVC is displayed from EditorVC, again push ReadVC on to the existing navigation controller. I believe this should resolve the issues that OP was seeing.

How to "virtually" tap back button in Navigation Bar

I have app, where is Segmented Control inside of my Navigation Bar. Under navigation bar I have 3 containers. In these containers I have Table View Controllers. If you tap on segmented control, one TVC appear and others disappear (container1.hidden = true and so on).
Problem is when I press "save" button which is also in navigation controller - button doesn't trigger "virtual push of back button".
I used following code which works in my other projects (its in button's action which is in VC that contains all container views) but not this time:
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
Image for better insight:
UPDATE: Thanks to # Alexey Bondarchuk I solved it. Comments may be confusing so I just recap problem and solution.
Originally, I had ViewController. To this controller I embed in Navigation Controller. To this Navigation Controller I connected segues. And that was mistake.
So I deleted this embed in navigation controller, made (show) segues directly to my View Controller (which is on screenshot). This automatically created navigation bar and last thing I did was that I put navigation item in it so now my code pop right navigationController. Hope that it's understandable.
I have couple ideas:
Your navigationController equal to 'nil' and .popViewControllerAnimated will never invoked. This may happen if you are using UITabBarController. In this case try to use self.tabBarController?.navigationController instead of self.navigationController.
Your controller presented 'Modally'. In this case you can try to invoke navController.dismissViewControllerAnimatedinstead of navController.popViewControllerAnimated

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.

bar button item segue not adding navigation bar at top of next view

When I drag to the next view controller to add a segue the new view controller has no navigation bar with a back button. I thought that was the default when you add a segue to a new VC. I'm also not able to drag a navigation bar to the top of the table view controller. Am I doing something wrong? Thanks.
Maybe the problem is the kind of segue that you are you using. The Segue type should be "Show (e.g Push)". Click on the segue and in the right panel go to the "attributes inspector" (the 4th one). And here you can check the type.
A view controller like in your case only shows a navigation bar by default, when the view controller itself or one of its parents (connected by a push-segue) is embedded in a navigation controller. Obviously, the navigation controller must not have hidden the navigation bar.
So, you either forgot to put a navigation controller into play or your segue is modal and not push.
Well, it's two years since you asked your question, but when it happened to me, I realized it was because at one point, I had accidentally created my segue as a different kind of segue (a detail one, I think), but changing it back to a "Show" segue didn't actually change it's behavior. When I found the segue in my storyboard xml, it was listed as a "Show" segue, but with a different custom action that suggested it was going to do something completely different.
Anyhoo, deleting and recreating the segue in Xcode fixed it. I probably could have also deleted that custom action in the xml file, too.

TabBarController in NavigationController does not show TabBar in viewControllers

I have a UITabBarController to whose controllers I would like to attach navigation. So I inserted the NavigationController as the entry controller, and the tabBarController as its root. All seems working fine, but for the tabBar. Basically it does not show, albeit the StoryBoard I attach seems to say differently. I also attach the Account Screen not showing any navigation bar nor, of course, any back button.
Thanks,
Fabrizio
Just a quick answer. I think you should put UINavigationController inside the TabBarController instead of the other way round. It will solve most of your problems.
Steps: Editor -> Embed in -> Navigation Controller
See the below screen shot on how to add a Navigation Controller to a View Controller.
You are following wrong approach, IOS does not allow you to use tabbarview controller as root of navigation controller, it always display black screen. I have faced same problem and as a solution i have added navigation bar after tabbar controller. Yes it becomes difficult to manage, but you can use that way and it will work.
If you use programmatic approach instead of storyboard then it is possible, see this link
Even you can try from Editor option of XCODE, select tabbar controller you have added from storyboad then go to Editor->Embedded in, you will see that navigation bar controller is disable.
This is also give you idea that it will not work.

Resources