gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:26:23 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com