我有一个按钮,我正在以编程方式添加到 UITableViewCell 中,它的行为非常奇怪。
在 iOS 6 中,它完全按预期工作。在 iOS 5x 中,它只响应 touch-down 事件而不响应 touch-up-inside 事件。甚至在你按住一两秒后才会触发着陆事件。
//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");
}
相当标准的问题代码。事实上,我使用这个确切的代码在我的应用程序中的所有地方制作按钮,它们都可以工作,除了在表格 View 中。关于细胞的结构,一定有一些我不理解的东西。
最佳答案
想通了。很久以前,出于另一个原因,我将 UITapGestureRecognizer 放在了桌面上。它干扰了按钮的功能。多谢你们。 (和女孩)
关于ios - UITableViewCell 中的 UIButton 在 iOS 5x 中没有响应但在 iOS 6 中响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13126447/