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

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

问题描述

我在 UIView 中有一个 UIButton,它位于我从 .xib 文件分配和初始化的 UIViewController 中.

I've got a UIButton in a UIView, which is in a UIViewController that I've allocated and inited from a .xib file.

当将 IBAction 连接到 UIButton 的Touch Down"事件时,它会正确触发.但是,如果我将它连接到Touch Up Inside"事件,它不会响应.

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.

其他事件也不起作用.'Touch Drag Enter'、'Touch Drag Exit'、'Touch Up Outside'等.仅Touch Down.

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?

该按钮是视图控制器中的一个简单的圆角矩形按钮.我已经加载了视图控制器:

The button is a simple rounded rectangle button in a view controller. I have loaded the view controller as such:

-(void) pushNewViewController
{
    MyViewController* newViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    [self.view addSubview:newViewController.view];
    [newViewController release];
}

我已在 IB 中将此按钮添加到 MyViewController 的圆角矩形按钮.我创建了以下 IBAction:

I've added this button to rounded rect button to MyViewController, in IB. I created the following IBActions:

-(IBAction) buttonTouchDown:(id)sender
{
    NSLog(@"Button Touch Down Event Fired.");
}

-(IBAction) buttonTouchUpInside:(id)sender
{
    NSLog(@"Button Touch Up Inside Event Fired.");
}

在 IB 我的菜单中单击按钮并将 Touch Down 出口拖到 MyViewController 并选择 buttonTouchDown:.保存了 IB xib.

In the IB I menu clicked on the button and dragged the Touch Down outlet to MyViewController and selected buttonTouchDown:. Saved the IB xib.

当我运行并测试按钮并获得Button Touch Down Event Fired"日志消息时.

When I run and test the button and get the "Button Touch Down Event Fired" log message.

但是当我回到 IB 并将 Action 更改为 Touch Up Inside 并将其连接到 buttonTouchUpInside: IBAction 并保存.我再次测试,我没有得到任何回应.

But when I go back to IB and change the Action to Touch Up Inside and hook it upto the buttonTouchUpInside: IBAction and save. I test again, I get no response.

问候,丰富

推荐答案

我很抱歉迟到了,但我遇到了完全相同的问题.在我的例子中,它是一个分配给父视图的 UITapGestureRecognizer.因此,最好同时检查识别器.

I'm sorry for being late but I have exactly the same problem. In my case it was a UITapGestureRecognizer assigned to parent view. So, it's good idea to check for recognizers as well.

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

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