Bagaimana tindakan untuk UIBarButtonItem kustom di Swift disetel?
Kode berikut berhasil menempatkan tombol di bilah navigasi:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:nil)
self.navigationItem.rightBarButtonItem = b
Sekarang, saya ingin menelepon func sayHello() { println("Hello") }
saat tombol disentuh. Upaya saya sejauh ini:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:sayHello:)
// also with `sayHello` `sayHello()`, and `sayHello():`
dan..
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:@selector(sayHello:))
// also with `sayHello` `sayHello()`, and `sayHello():`
dan..
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:@selector(self.sayHello:))
// also with `self.sayHello` `self.sayHello()`, and `self.sayHello():`
Catatan yang sayHello()
muncul di Intellisense, tapi tidak berhasil.
Terima kasih atas bantuan Anda.
EDIT: Untuk anak cucu, karya berikut:
var b = UIBarButtonItem(title: "Continue", style: .Plain, target: self, action:"sayHello")
action: "sayHello"