1

我有一个按钮,我正在以编程方式添加到 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");
}

相当标准的问题代码。事实上,我使用这个确切的代码在我的应用程序中的所有地方制作按钮,它们都可以工作,除了在表格视图中。关于细胞的结构,一定有一些我不理解的东西。

4

1 回答 1

5

想通了。很久以前,出于另一个原因,我将 UITapGestureRecognizer 放在了桌面上。它干扰了按钮的功能。多谢你们。(和女孩)

于 2012-10-29T18:57:14.563 回答