Have a look at this example code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let letterButton = UIButton.buttonWithType(.Custom) as UIButton
self.view.addSubview(letterButton)
letterButton.addTarget(self, action:Selector("buttonDidTap:"), forControlEvents: .TouchUpInside)
}
func buttonDidTap(button: UIButton!) {
print(button.char)
}
}
The target action for the UIButton
works fine as long as Selector is public or internal, but if it's private, it crashes due to unrecognized selector sent to instance
Is there any way I can achieve this ? I don't want to make tap function public or internal.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…