UIButton 事件“Touch Up Inside”不工作。 “着陆”工作正常
我在 UIView 中有一个 UIButton,它位于我从 .xib 文件分配和初始化的 UIViewController 中。
当将 IBAction 与 UIButton 的“Touch Down”事件挂钩时,它会正确触发。但是,如果我将其连接到“Touch Up Inside”事件,它不会响应。
其他事件也不起作用。 “触摸拖动进入”、“触摸拖动退出”、“触摸向外”等。仅触摸向下。
有谁知道为什么会这样?
富有的
I've got a UIButton in a UIView, which is in a UIViewController that I've allocated and inited from a .xib file.
When hooking an IBAction up to the 'Touch Down' event of a UIButton it triggers correctly. But if I hook it up to the 'Touch Up Inside' event it doesn't respond.
Other events don't work either. 'Touch Drag Enter', 'Touch Drag Exit', 'Touch Up Outside' etc. Only Touch Down.
Does anyone have any idea why this might be?
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我可以绝对、积极地向您保证,IB 中正确连接的 UIButton 会按预期响应内部触摸事件。 (你能想象如果他们没有这样做吗?!)
鉴于此,可以肯定的是,你没有按照你的预期将事情连接起来。这里有一些可以尝试的事情:
首先让你的操作打印日志语句:
NSLog(@"%s", __PRETTY_FUNCTION__);
在 IB 中检查您的按钮连接到的唯一功能是您的 touch-up inside 操作。 (稍后,您可以将其连接到多个事件,但是为了测试,我们希望尽可能地简化。)
确保您的操作具有正确的签名:
- (IBAction) myButtonPressedAction: (id) sender;
为了确保一切都干净,请从 .xib 中删除按钮并重新添加它。
userInteractionEnabled
。如果这些都没有帮助,您将不得不告诉我们有关问题区域的更多信息。也许添加 IB 中按钮设置的屏幕截图和项目中的代码片段。
First, I can absolutely, positively guarantee you that UIButtons correctly connected in IB responds as expected to touch-up-inside events. (Can you imagine if they didn't?!)
Given that, it's a fair bet that you have not hooked things up as you expect. Here are some things to try:
Make your action print a log statement first thing:
NSLog(@"%s", __PRETTY_FUNCTION__);
Check in IB that the ONLY function that your button is wired to is your touch-up-inside action. (Later, you can wire it to multiple events but, for testing, we want to simplify as much as possible.)
Make sure you have the correct signature for your action:
- (IBAction) myButtonPressedAction: (id) sender;
Just to be sure everything's clean, delete the button from your .xib and re-add it.
userInteractionEnabled
set.If none of that helps, you'll have to tell us more about the problem area. Perhaps add a screenshot of your button setup in IB and code snippets from your project.