UIButton event 'Touch Up Inside' not working. 'Touch Down' works fine

我是研究僧i 提交于 2020-01-15 05:33:26

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3884591/uibutton-event-touch-up-inside-not-working-touch-down-works-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!