- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = self.view.bounds;
[button addTarget:self action:@selector(aaa) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(bbb) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)aaa{
NSLog(@"aaa");
}
- (void)bbb {
NSLog(@"bbb");
}
结果就是两个都会运行 输出:
2017-09-12 19:09:15.288240+0800 pinglun[18874:4238746] aaa
2017-09-12 19:09:15.288443+0800 pinglun[18874:4238746] bbb
可以使用removeTarget方法移除
[button removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];