本文介绍了栏栏按钮项目未显示在navigationBar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我的初始视图控制器嵌入在导航控制器和标签栏控制器中。

I'm working on an app where my initial view controller is embedded in a Navigation Controller and Tab bar controller.

在我的应用中,我有3个不同的标签,一个标签是设置视图。这是一个带5个按钮的tableview。每个按钮在触摸时都会显示相同的视图控制器。

In my app I have 3 different tabs, one tab is the settings view. This is a tableview with 5 buttons. every button will show the same view controller when it's touched.

当我触摸其中一个按钮时,我仍然有一个漂亮的绿色导航栏,但我的按钮不起作用。

When I touch on one of the buttons, I still have a nice green navigation bar, but my buttons do not work.

我尝试将导航项拖到我的故事板中的视图中,然后在其中放置一个条形按钮项。我可以看到我的故事板中的按钮,但是当我运行它时它不会显示在我的应用程序中。

I tried dragging a Navigation Item into the view in my storyboard and then put a bar button item in it. I can see the button in my storyboard, but it won't show up in my app when I run it.

我还将以下代码添加到我的viewDidLoad() :

I also added the following code to my viewDidLoad():

let leftItem = UIBarButtonItem(title: "< Back", style: .Done, target: self, action: Selector("Save"))
let rightItem = UIBarButtonItem(title: "Save", style: .Plain, target: self, action: Selector("Save"))

//self.parentViewController?.navigationItem.leftBarButtonItem = leftItem // also doesn't work

navigationController?.navigationItem.leftBarButtonItem = leftItem
navigationController?.navigationItem.rightBarButtonItem = rightItem

但它不会有任何影响。

我检查了在故事板中为我的视图分配了正确的UIViewController,做了几个Clean构建(CMD + Shift + K)和Rebuilds(CMD + B)。

I checked if the correct UIViewController was assigned to my view in the storyboard, did several Clean builds (CMD + Shift + K) and Rebuilds (CMD + B).

以下图片是我的故事板的一部分的屏幕截图和我的应用程序的屏幕截图在按钮不会显示的视图上。

The following images are a screenshot of a part of my storyboard and a screenshot of my app at the view where the buttons won't show up.

编辑

添加了有关视图中控件的新屏幕截图。如果没有我的viewDidLoad中的其他代码,这些不适用于

Added a new screenshot about the controls in the view. These do not work with or without the additional code in my viewDidLoad.

推荐答案

删除你的第一个导航控制器,第二个你不需要添加后退按钮只需使用push segue,第三个尝试使用self.navigationItem.leftBarButtonItem (尝试在开头添加自我。)*原始答案是评论。

Delete your first navigation controller, second you dont need to add back button just use push segue, third try to use self.navigationItem.leftBarButtonItem(try adding self at the beginning.) *Original answer was a comment.

这篇关于栏栏按钮项目未显示在navigationBar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 11:58