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

前端 未结 7 1686
北恋
北恋 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:08

    Dear i faced the same problem. When i tapped the cell but didselectrowatindexpath was not called than it was suddenly called when i released the button after pressing it for few seconds.

    If you are facing the same issue there must be a 1. UITapGestureRecognizer that is creating problem for you or 2. a scroll view in which you placed you table view.

    Thus you should remove the gesture or the super scroll view in which your table view is placed

    0 讨论(0)
  • 2020-12-09 08:14

    same problem happened with me because I have added a tap gesture recogniser over it. If you have used any gesture recognizer try removing it and check if it causing the problem.

    EDIT: Solution as commented by the Ali: If you have used tap gesture you can use [tap setCancelsTouchesInView:NO];

    0 讨论(0)
  • 2020-12-09 08:16

    I was faced with a similar issue:

    For me, the problem was because my UITableView was added to an UIScrollView and more specifically to its contentView. It appears that inside the contentView, I had to stay press 2-3 sec to fire the didSelectRowAtIndexPath method.

    I moved my TableView to self.view instead of contentView and it solved the problem!

    0 讨论(0)
  • 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)
        }
     }
    
    0 讨论(0)
  • 2020-12-09 08:33

    I'm not sure about this, but Delays Content Touches might have something to do with it.

    0 讨论(0)
  • 2020-12-09 08:34

    If you have custom gesture object on your view, check override func gestureRecognizerShouldBegin(_ gesture: UIGestureRecognizer) -> Bool delegate. Compare custom gesture with sender gesture, If its not custom gesture object, pass it to the the super. So system gestures/taps won't get blocked.

    0 讨论(0)
提交回复
热议问题