【发布时间】:2016-01-30 19:21:57
【问题描述】:
我很难在 swift 中向工具栏添加按钮,您可以在下面看到我所追求的工具栏的图像,不幸的是,即使我在我的 Storyboard 文件中设计了它,但它并没有将工具栏设置为可见时显示。
我设计这个的方式是两个项目,第一个是flexable space 元素,第二个是add 元素。它看起来像这样:
这是我用来尝试在代码中复制它的代码:
self.navigationController?.toolbarHidden = false
self.navigationController?.toolbarItems = [UIBarButtonItem]()
self.navigationController?.toolbarItems?.append(
UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil)
)
self.navigationController?.toolbarItems?.append(
UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "onClickedToolbeltButton:")
)
如您所见,我将工具栏设置为可见,初始化(并清除)UIBarButtonItem 的 toolbarItems 数组,然后以正确的顺序将两个 UIBarButtonItem 添加到数组中。
但是,工具带仍然是空的,这是为什么呢?
【问题讨论】: