Reputation: 9544
I have a button I'm adding in a UITableViewCell programmatically and it is behaving very strangely.
In iOS 6 it works exactly as expected. In iOS 5x it only responds to touch-down events and not touch-up-inside events. 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.
Upvotes: 1
Views: 782
Reputation: 9544
Got it figured out. Long long ago I had put a UITapGestureRecognizer on the table for another reason. It was interfering with the button's functionality. Thanks guys. (and gals)
Upvotes: 5