如何将 barButtonItem 添加到 ToolBar

How to add barButtonItem to ToolBar

如何转换此代码以使按钮出现在工具栏中? :

navigationItem.rightBarButtonItem = editButtonItem()

试试这个,

    let barButtonItem = UIBarButtonItem(title: "Edit", style: .Plain, target: self, action: "onEditButtonTapped:")
    self.navigationItem.rightBarButtonItem = barButtonItem

然后像这样写动作函数,

    func onEditButtonTapped(sender:UIBarButtonItem) {
        ...
    } 

试试这个:

    self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonItemStyle.Plain, target: self, action: "btnClicked:"), animated: true)


  //adding function to bar button

    func btnClicked(sender: UIBarButtonItem)
     {
        //your code here
     }