【发布时间】:2014-09-20 00:05:52
【问题描述】:
我正在使用 XCode 我在导航控制器中添加了一个工具栏。我想将条形按钮添加到该工具条。 在我的故事板中,我尝试将“条形按钮项”控制拖动到工具栏,但这不起作用,没有添加任何内容。
那么可以'Bar Button Item'到工具栏吗?
谢谢。
更新:
我添加了自己的 UINavigationController,将故事板中的工具栏绑定到我的类作为“mytoolbar”。 并迅速给出了答案代码, 但是当我在模拟器上运行它时,我没有看到任何工具栏项。
class AppNavigationController: UINavigationController {
@IBOutlet weak var mytoolbar: UIToolbar!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
var rightButton = UIBarButtonItem(title: "Title", style: UIBarButtonItemStyle.Plain, target: self, action: Selector("method"))
var items = [AnyObject]()
items.append(rightButton)
mytoolbar.items = items
}
func method() {
println("Something cool here")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】: