简体   繁体   中英

Tab bar controller is not showing bar button item

I'm new in Objective-C, and even more using storyboards. This being said I'm trying to use a bar button item within UITabBarController and UINavigationController as can you see in the image below. 在此输入图像描述

But once I run the project in simulator this item is not showing. I would appreciate a non programmatically solution if it's posible.

在此输入图像描述

After I spent a while trying to get the best way to do it I finally did that I should have done since begin. Read official apple documentation .

Parameters

viewController The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the stack.

In other words, my approach is just a bad design.

Okay, so the way to do this:

When you create your tab view controller. You have to add a navigation controller that will handle each tab.

Tab View Controller --> navigation controller --> View Controller 1.

Then add the bar button item to view controller 1. Then go ahead and add the segues.

Now, still it won't show up.

But, if you go to your code for your view controller 1: Add a reference from the storyboard of your bar button item into your View Controller 1 file. Then, in ViewWillAppear():

self.tabBarController.navigationItem.rightBarButtonItem = _btnNewContact;

From there, it will show up and the segue you have configured in your storyboard should work perfectly! =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM