views:

72

answers:

2

I have a UIButton defined within a tableviewCellWithReuseIdentifier.

The button works but it's very touchy. If I just tap the button it works. Pressing it any long fails to trigger the action, even though it does flash showing that it knows it was pressed. Why is this happening? More importantly, how can I fix it.

Here is the code for the UIButton within the cell.

CGRect rect = CGRectMake(190.0, 2.0, 40.0, ROW_HEIGHT);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTag:LBUTTON_TAG];
[button setFrame:rect];
[button addTarget:self action:@selector(leftbutton:) forControlEvents:UIControlEventTouchUpInside];
[button setAlpha:0.5];
[cell addSubview:button];
A: 

Possibly because your finger is moving slightly so UIScrollView (which UITableView is a subclass of) thinks it's a drag?

Try setting tableView.canCancelContentTouches = NO.

tc.
Tried that, but that didn't work. It does the same thing in the simulator too.
John Smith
+1  A: 

A long shot, but: do you have any asynchronous background processes that might be calling [tableView reloadData] between tap-down and tap-up? That might cause UITableViewCell's mouse tap handling to reset some internal data that makes it "forget" the tap-down inside the button, which could cause it to not fire the UIControlEventTouchUpInside event since it doesn't remember the tap-down.

TroutKing
You are exactly right. I had an NSTimer running and as soon as I switched it off life was good. Thanks!
John Smith