iphone - 如何在一个方法中捕获并处理 UIButton 的所有事件?

标签 iphone ios ipad uibutton uievent

我想为一个 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/

相关文章:

iphone - 如何快速在相机上添加圆形 mask

iphone - 设备 (iPad) 上 OpenGL 纹理中的视觉伪影 - 但模拟器上没有

iphone - iOS View 动画

ios取消NSURLConnection Swift

ios - 为什么使用 AVCaptureSession、AVAssetWriter 和 AVPlayer 录制和重放视频会卡顿?

ios - performSegueWithIdentifier 不起作用 - Swift

objective-c - iPad 3 慢截图

ios - 带有图像背景的 iOS 7 中的 UITableViewCell 问题

iphone - 迁移核心数据——如何安全地迁移?

iphone - UIViewController 加载旋转为横向但仅支持纵向