简体   繁体   English

标签栏控制器未显示栏按钮项

[英]Tab bar controller is not showing bar button item

I'm new in Objective-C, and even more using storyboards. 我是Objective-C的新手,甚至更多使用故事板。 This being said I'm trying to use a bar button item within UITabBarController and UINavigationController as can you see in the image below. 这就是说我正在尝试使用UITabBarController和UINavigationController中的一个条形按钮项,如下图所示。 在此输入图像描述

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. viewController被压入堆栈的视图控制器。 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. 选项卡视图控制器 - >导航控制器 - >查看控制器1。

Then add the bar button item to view controller 1. Then go ahead and add the segues. 然后添加条形按钮项目以查看控制器1.然后继续添加segue。

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. 但是,如果您转到视图控制器的代码1:将条形按钮项的故事板中的引用添加到View Controller 1文件中。 Then, in ViewWillAppear(): 然后,在ViewWillAppear()中:

self.tabBarController.navigationItem.rightBarButtonItem = _btnNewContact;

From there, it will show up and the segue you have configured in your storyboard should work perfectly! 从那里开始,它会出现,你在故事板中配置的segue应该可以完美运行! =) =)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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