如何在Swift中设置自定义UIBarButtonItem的操作?
以下代码将按钮成功放置在导航栏中:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:nil)
self.navigationItem.rightBarButtonItem = b
现在,我想func sayHello() { println("Hello") }
在触摸按钮时打电话。到目前为止,我的努力:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:sayHello:)
// also with `sayHello` `sayHello()`, and `sayHello():`
和..
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:@selector(sayHello:))
// also with `sayHello` `sayHello()`, and `sayHello():`
和..
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:@selector(self.sayHello:))
// also with `self.sayHello` `self.sayHello()`, and `self.sayHello():`
请注意,它sayHello()
出现在智能感知中,但不起作用。
谢谢你的帮助。
编辑:为后代,以下作品:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:"sayHello")
action: "sayHello"