如何在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")
https://stackoverflow.com/questions/24641350
复制相似问题