在我们使用
Objective-c
时经常使用SEL
来执行某些操作。那么在Swift
中如何使用呢?在Swift
中是用#selector
表示,#selector(MyViewController.tappedButton(sender:))
例如:
- Objective-c
UIButton *myButton = [UIButton new];
[myButton addTarget:self action:@selector(clickmyButton:) forControlEvents:UIControlEventTouchUpInside];
- Swift
let action = #selector(MyViewController.clickmyButton)
myButton.addTarget(self, action: action, forControlEvents: .touchUpInside)