我在UITableViewCell中添加了UIScrollView,但是当我点击滚动视图时,确实没有调用select方法.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
我在cellView的contentView上添加滚动视图,仍然没有调用select方法.
[cell.contentView addSubview:scrollView];
解决方法
因为scrollView重叠在Cell上…最好的方法是在UIScrollView上添加tap Gesture,比如
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; [recognizer setNumberOfTapsrequired:1]; MYScrollView.userInteractionEnabled = YES; [MYScrollView addGestureRecognizer:recognizer];
在cellForRowAtIndexPath方法和Write手势动作方法中添加上面的代码就好了
-(void)gestureAction:(UITapGestureRecognizer *) sender { CGPoint touchLocation = [sender locationOfTouch:0 inView:self.YourTableViewName]; NSIndexPath *indexPath = [self.YourTableViewName indexPathForRowAtPoint:touchLocation]; NSLog(@"%d",indexPath.row); }
在上面的gesture(action)方法中,您可以将indexPath与didSelectRowAtIndexPath相同.