我想为一个 View 的所有按钮(及其所有事件)使用单一方法。到目前为止,这就是我所拥有的:
- (IBAction)uibuttonEvent:(id)idSender forEvent:(UIEvent*)uieventHandle
{
if (idSender == [self uibuttonConnectInput]) {
if ([uieventHandle type] == UIEventTypeTouches) {
[[self uibuttonConnectInput] setTitle:@"did it!" forState:UIControlStateNormal];
}
} else if (idSender == [self uibuttonSomething]) {
...
}
}
所以现在我可以检测事件是否是 UIEventTypeTouches
或不是,但我想更具体地检查它是否是,例如UIControlEventTouchUpInside
- 我该怎么做?
最佳答案
讨论 here您从 UIButton 获得的 UIEvent 不会为您提供有关哪个 UIControlEvent 导致它的任何信息。为每个事件类型注册单独的方法(推荐的解决方案)或创建您自己的 UIControl 子类并使其行为不同。
关于iphone - 如何在一个方法中捕获并处理 UIButton 的所有事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8532444/