didSelectRowAtIndexPath: not being called

前端 未结 14 2179
轻奢々
轻奢々 2020-11-29 18:57

I have a UITableView as a subview of my UIScrollVIew, which is the main view controlled by my MainViewController.

In MainView

相关标签:
14条回答
  • 2020-11-29 18:59

    My solution is :

    1. set cancelsTouchesInView To No of any tapGesture

    2. I found in my custom cell , userInteractionEnable is set to NO, simply delete userInteractionEnable = No and issue solved.

    0 讨论(0)
  • 2020-11-29 19:02

    I have found the answer. I had a UITapGestureRecognizer set for myTableView's superView. This overrode the selection call. Credit to whoever suggested that that might be it. Your answer was deleted before I could mark it correct.

    Set the cancelsTouchesInView property to NO on the gesture recogniser to allow the table view to intercept the event.

    0 讨论(0)
  • 2020-11-29 19:02

    Have you defined instance variable for tableview with same name. If not then might be this can be the issue-

    _myTableView.delegate = self;
    _myTableView.datasource = self;
    

    Or-

    self.myTableView.delegate = self;
    self.myTableView.datasource = self;
    
    0 讨论(0)
  • 2020-11-29 19:07

    My problem is the cell is a customized cell, and the action does not work on it. In addition, there is a UITapGestureRecognizer defined in the superclass.

    Firstly, Set tapGesture.cancelsTouchesInView = false

        override func viewDidLoad() {
            super.viewDidLoad()
            
            initUI()
            let tapGesture = UITapGestureRecognizer(target: self, action: #selector(endEditing))
            tapGesture.cancelsTouchesInView = false
            view.addGestureRecognizer(tapGesture)
        }
    

    Secondly, Instead of setting isUserInteractionEnabled = true; in the table view, I set the action on the cell.

    In the ViewDidLoad()

            super.viewDidLoad()
            
            tableView.delegate = self
        }
    

    Then in the

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            let cell: UITableView = tableView.dequeueReusableCell(for: indexPath)
            cell.isUserInteractionEnabled = true;
    

    You can try this solution if you are creating a customized cell.

    0 讨论(0)
  • 2020-11-29 19:07

    It's work for me, can you try!

    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard)) tap.cancelsTouchesInView = false view.addGestureRecognizer(tap)

    0 讨论(0)
  • 2020-11-29 19:09

    My case is strange. My tableView has 2 sections. 1st section's cells work fine about tableView:didSelectRowAt:, but 2nd section's cells doesn't trigger didSelectRowAt:.

    The above problem happens at iPhone 4s, iOS 9.3. But in iPhone 5s, iOS 10.3, there are no problems, those cells works fine. It seems like iOS 9 bugs about UITableView.

    After many tests, I found out one line codes produces this bug.

    tableView.estimatedSectionHeaderHeight = 60.0
    

    Because the 2nd sections has no header view. I remove this line, and all works fine.

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