【问题标题】:Add a button to the native toolbar向本机工具栏添加按钮
【发布时间】:2017-03-08 05:09:31
【问题描述】:

我有以下代码

final class MyViewController: UIViewController, 
    UICollectionViewDataSource, UICollectionViewDelegate, /*..*/ {

    //
    // Declaring local variables, other controllers and delegates etc.
    //

    override func viewDidLoad() {
        super.viewDidLoad()

        let item = UIBarButtonItem(title: "A button that should do nothing", 
            style: .Plain, target: nil, action: nil)

        self.navigationController!.toolbar.items = [item]

        self.navigationController!.toolbarHidden = false
    }

    // the rest of my code
}

无论我做什么,工具栏都会出现,但里面什么都不会渲染。

我也试过

self.navigationController?.toolbarItems?.insert(item, atIndex: 0)

进行项目的插入,但仍然没有运气。

我做错了什么?

【问题讨论】:

    标签: ios swift uinavigationcontroller uitoolbar


    【解决方案1】:

    通过添加项目修复

    self.toolbarItems = [item]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多