UIButton oversensitive
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 presse开发者_C百科d. 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 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.
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
.
精彩评论