UIButton 事件“Touch Up Inside”不工作。 “着陆”工作正常

发布于 2024-09-26 05:21:25 字数 250 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡间太子 2024-10-03 05:21:25

首先,我可以绝对、积极地向您保证,IB 中正确连接的 UIButton 会按预期响应内部触摸事件。 (你能想象如果他们没有这样做吗?!)

鉴于此,可以肯定的是,你没有按照你的预期将事情连接起来。这里有一些可以尝试的事情:

  • 首先让你的操作打印日志语句:

    NSLog(@"%s", __PRETTY_FUNCTION__);​​

  • 在 IB 中检查您的按钮连接到的唯一功能是您的 touch-up inside 操作。 (稍后,您可以将其连接到多个事件,但是为了测试,我们希望尽可能地简化。)

  • 确保您的按钮为 50x50 或更大。 (小按钮很难按。)
  • 现在,将按钮设置为圆角矩形按钮。如果您有一个图像按钮,并且图像具有透明度,则可能很难按下。
  • 确保您的操作具有正确的签名:

    - (IBAction) myButtonPressedAction: (id) sender;

  • 为了确保一切都干净,请从 .xib 中删除按钮并重新添加它。

  • 确保父视图已设置userInteractionEnabled
  • 确保 xib 的 FileOwner 是您的视图控制器类型。

如果这些都没有帮助,您将不得不告诉我们有关问题区域的更多信息。也许添加 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 your button is 50x50 or bigger. (Small buttons are hard to press.)
  • For now, make your button a rounded-rect button. If you had an image button, and the image has transparency, it may be hard to press.
  • 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.

  • Make sure the parent view has userInteractionEnabled set.
  • Make sure that the xib's FileOwner is your view-controller type.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文