UIButton 事件“Touch Up Inside”不工作。 “着陆”工作正常
我在 UIView 中有一个 UIButton,它位于我从 .xib 文件分配和初始化的 UIViewController 中。
当将 IBAction 与 UIButton 的“Touch Down”事件挂钩时,它会正确触发。但是,如果我将其连接到“Touch Up Inside”事件,它不会响应。
其他事件也不起作用。 “触摸拖动进入”、“触摸拖动退出”、“触摸向外”等。仅触摸向下。
有谁知道为什么会这样?
该按钮是视图控制器中的一个简单的圆角矩形按钮。 我已经这样加载了视图控制器:
-(void) pushNewViewController
{
MyViewController* newViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[self.view addSubview:newViewController.view];
[newViewController release];
}
我已将此按钮添加到 IB 中的 MyViewController 的圆角矩形按钮。 我创建了以下 IBActions:
-(IBAction) buttonTouchDown:(id)sender
{
NSLog(@"Button Touch Down Event Fired.");
}
-(IBAction) buttonTouchUpInside:(id)sender
{
NSLog(@"Button Touch Up Inside Event Fired.");
}
在 IB I 菜单中单击按钮并将 Touch Down 出口拖动到 MyViewController 并选择 buttonTouchDown:。保存了 IB xib。
当我运行并测试按钮并收到“按钮触地事件已触发”日志消息时。
但是,当我返回 IB 并将操作更改为 Touch Up Inside 并将其连接到按钮TouchUpInside: IBAction 并保存时。我再次测试,没有任何反应。
问候, 富有的
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?
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];
}
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.");
}
In the IB I menu clicked on the button and dragged the Touch Down outlet to MyViewController and selected buttonTouchDown:. Saved the IB xib.
When I run and test the button and get the "Button Touch Down Event Fired" log message.
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.
Regards,
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
很抱歉迟到了,但我也有同样的问题。就我而言,它是分配给父视图的
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.您正在释放 newViewController。
虽然添加 newViewController.view 作为子视图将保留该视图,但 newViewController 对象的保留计数将为 0。
You're releasing newViewController.
While the adding the newViewController.view as a subview will retain the view, the newViewController object will have a retain count of 0.
你提到储蓄;进行更改后,您是否保存了 xib 和 MyViewController 文件?通常,当类似的事情对我不起作用时,我发现我没有保存 IB 中的 xib 或 XCode 中的类文件。
You mentioned saving; did you save both the xib and your MyViewController files after you made your changes? Often when something like this stops working for me, I find that I didn't save either the xib in IB or the class file in XCode.
你有没有实现触摸事件处理程序
你的MyViewController的代码?
看起来你的 UIButton 只接收到 TouchBegan
事件并且该事件被之前的某些事件取消
它可以接收touchesEnded。
像 UIScrollView 这样的东西通常会在
决定需要转发到的触摸
它是子视图和应该由其处理的拖动
本身。
Do you have any touch-event handlers implemented in
your MyViewController's code?
It looks like your UIButton only receives touchesBegan
event and the event gets cancelled by something before
it could receive touchesEnded.
Something like UIScrollView usually does when it's
deciding between touch that needs to be forwarded to
it's subviews and a drag that should be handled by
itself.
哈哈,这是一个愚蠢的解决方案,但在 xib 中,我将其链接到外部的buttonTouchUp,这导致了问题。也许这会有所帮助:)
Lol well this was dumb solution, but in the xib I had it linked to buttonTouchUp outside, and that was causing the problem. Maybe this will help :)