Reputation: 1820
I have two UIButtons in table cells that inconveniently press when scrolling. How can I prevent this?
Is there some property or sent event I can set so the button is only pressed when a user releases the press rather than as soon as the button is pressed?
I played around with the different touch events (Touch Up Inside and Touch Down) and neither seemed to resolve this issue.
Upvotes: 2
Views: 1462
Reputation: 14841
In interface builder change the tag values of the buttons to a number greater than 10 (or some value). Subclass UIScrollView and override:
-(BOOL) touchesShouldCancelInContentView:(UIView *)view {
if(view.tag>10) {
NSLog(@"should A");
return YES;
} else return NO;
}
Your scrollView should have the property canCancelContentTouches
set to YES and delaysContentTouches
set to NO
Upvotes: 0
Reputation: 5552
You can listen for the tableview's scrolling delegate callbacks and turn off your buttons they are being scrolled
- (void)scrollViewWillBeginDragging:(UIScrollView *)activeScrollView {
//I assume the buttons are within your cells so you will have to enable them within your cells so you will probably have to handle this by sending a custom message to your cells or accessing them with properties.
[yourButton setEnabled: NO];
}
and listen for
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
// do the same to enable them back
[yourButton setEnabled: YES];
}
Upvotes: 3