UIButton事件“Touch Up Inside”不起作用“Touch Down”工作正常 [英] UIButton event 'Touch Up Inside' not working. 'Touch Down' works fine

查看:521
本文介绍了UIButton事件“Touch Up Inside”不起作用“Touch Down”工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIView中有一个UIButton,它在一个UIViewController中,我已经从.xib文件中分配和输入了。



当挂起IBAction直到UIButton的Touch Down事件才能正确触发。但是如果我把它连接到'Touch Up Inside'事件,它就不会响应。



其他事件也不起作用。 触摸拖动输入,触摸拖动退出,向外触摸等。只能向下触摸。



有没有人知道为什么会这样? p>

Rich

解决方案

首先,我绝对保证,UIButtons在IB中正确连接将按预期的方式响应内部事件。 (你可以想象,如果他们没有?)



鉴于这一点,公平的说,你没有按照你的期望挂钩事情。以下是一些要尝试的事情:




  • 使您的操作打印日志声明第一件事:



    NSLog(@%s,__PRETTY_FUNCTION __);


  • 在IB中,您的按钮被连接到的ONLY功能是您的内部操作。 (稍后,您可以将其连接到多个事件,但为了测试,我们希望尽可能简化。)


  • 确保您的按钮为50x50或更大。 (小按钮很难按。)

  • 现在,让你的按钮是一个圆角的按钮。如果您有图像按钮,并且图像具有透明度,可能很难按。

  • 确保您的操作具有正确的签名:



    - (IBAction)myButtonPressedAction :( id)sender;


  • p>只是为了确保一切都很干净,删除.xib中的按钮并重新添加它。


  • 确保父视图具有 userInteractionEnabled set

  • 确保xib的FileOwner是您的视图控制器类型。



如果没有帮助,您将不得不告诉我们更多关于问题的区域。也可以在IB中添加按钮设置的屏幕截图,并从您的项目中添加代码片段。


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

解决方案

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.

这篇关于UIButton事件“Touch Up Inside”不起作用“Touch Down”工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆