简体   繁体   English

UITableViewCell中的UIButton在iOS 5x中不响应,但在iOS 6中响应

[英]UIButton in UITableViewCell not responding in iOS 5x but responding in iOS 6

I have a button I'm adding in a UITableViewCell programmatically and it is behaving very strangely. 我有一个按编程方式添加到UITableViewCell中的按钮,它的行为非常奇怪。

In iOS 6 it works exactly as expected. 在iOS 6中,它完全可以按预期运行。 In iOS 5x it only responds to touch-down events and not touch-up-inside events. 在iOS 5x中,它仅响应触地事件,而不响应触地内部事件。 And even the touch down event only fires after you hold down for a second or two. 甚至按下事件仅在按住一两秒钟后才会触发。

//Create UIButton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTap) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(0, 0, 100, 100);

//Add to UITableViewCell
UITableViewCell *footerCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FOOTER_CELL"] autorelease];
[footerCell.contentView addSubview:button];
//Also tried this with just [footerCell addSubview:button];

//Fire Action
- (void)buttonTap {
    NSLog(@"Tap");
}

Pretty standard issue code. 相当标准的发行代码。 In fact I use this exact code to make buttons all over the place in my app and they all work, except in the table view. 实际上,我使用此确切的代码在应用程序中的各处制作了按钮,除了在表视图中,它们都可以正常工作。 There's got to be something I'm not understanding about the structure of the cell. 关于单元格的结构,我有些不了解。

Got it figured out. 明白了。 Long long ago I had put a UITapGestureRecognizer on the table for another reason. 很久以前,出于另一个原因,我将UITapGestureRecognizer放在桌子上。 It was interfering with the button's functionality. 它干扰了按钮的功能。 Thanks guys. 多谢你们。 (and gals) (和女孩)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM