UITableView grabbing touch events from subviews
I have a UITableView, which loads UIViews into its cells. These UIViews开发者_Python百科 use the -touchesBegan:withEvent: etc methods, which all work fine & let me implement code to move these subviews around in the table. This all works, until I move my finger vertically & start scrolling the table, then the UIViews stop receiving any touch events. If anyone knows how to get around this I'd be very happy! Many thanks.
-(void)ViewDidLoad
{
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped)];
tapped.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapped];
[tapped release];
}
-(void)tapped
{
NSLog(@"TAPPED");
}
The parent UIScrollView of your UITableView might take over responding to your touch events.
Just forward the event to your custom subviews.
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if ([touches count] == 1)
{
//Your code here than should return if it reacts to touch
}
//forwarding action:
[self.nextResponder touchesBegan:touches withEvent:event];
}
Source: Touch forwarding on uitableview?
Old topic but I was struggling with the same issue (UITableView as a subview to UITableView). Just disable the scrolling for the "parent" UITableView with the scrollEnabled = NO. That will stop the vertical scrolling.
精彩评论