如何在单个UIButton中添加多个动作?生活,例如,
[btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
[btn addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchDown];
由于
答案 0 :(得分:8)
您粘贴的代码应该有效:
[btn addTarget:self action:@selector(method1) forControlEvents:UIControlEventTouchUpInside];
[btn addTarget:self action:@selector(method2) forControlEvents:UIControlEventTouchDown];
我一直这样做。通常用于touchDown和touchUp。没有调用method2的事实是一个bug。你在method2的开头有一个NSLog()吗?
答案 1 :(得分:2)
[btn addTarget:self action:@selector(method1and2) forControlEvents:UIControlEventTouchUpInside];
…
- (void)method1and2 {
[self method1];
[self method2];
}