UITapGestureRecognizer與didSelectRowAtIndexPath衝突解決

weixin_33924312發表於2016-02-25

需求要做一個這樣的下拉彈窗 點選彈窗選中Cell 點選其他區域彈窗消失

36564-1891c6994cc90fa7.png
111.png

貼程式碼

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onTapDissMissSelf)];
      
      
      self.userInteractionEnabled = YES;
      
      tap.delegate = self;
      
      
      [self addGestureRecognizer:tap];

解決衝突程式碼 這個是UIGestureRecognizerDelegate 代理方法

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {//如果當前是tableView
        //做自己想做的事
        return NO;
    }
    return YES;
}

相關文章