iphone - didSelectRowAtIndexPath: only being called after long press on custom cell

前端 未结 7 1715
北恋
北恋 2020-12-09 08:07

I am creating one table view based application. I have created a custom table cell for table, that contains 2 labels, 1 image and 1 button. The table view Data source metho

7条回答
  •  清歌不尽
    2020-12-09 08:19

    As others suggested, [tap setCancelsTouchesInView:NO]; does the trick. However, I want to make one thing clear:

    If you think that you did not implement tapgesture and are curious about why you had to add your view into the protected views, check out your class because most probably you have inherited some class and that class includes tap gesture recognizer in it.

    In my case, I did the following:

    - (NSMutableArray *)tapProtectedViews
    {
        NSMutableArray *views = [super tapProtectedViews];
        [views addObject:self.mTableView];
        return views;
    }
    

    Edit for Swift 4+

    Assuming you have a UITapGestureRecognizer instance named tapGesture:

    func disableTapGesture(){
        tapGesture.cancelsTouchesInView = false
    }
    

    Or you can:

    if self.view.gestureRecognizers?.isEmpty == false{
        for recognizer in self.view.gestureRecognizers!{
            self.view.removeGestureRecognizer(recognizer)
        }
     }
    

提交回复
热议问题