Swift DidSelectRowAt not firing

2019-06-03 15:24发布

I have a project with a few different VCs...two of them have TableViews

The first one works perfectly fine, I have a custom view in there etc.

The second one is also custom and it fill the information in just fine, but unlike the first one...I cannot tap on it to segue to the next VC

I have the Delegate and DataSource set up properly. I have another VC on my project with a tableview and it works just fine. The first thing I can think might be preventing it from working is a UILabel takes up 90% of the cell, but I don't think that is it because I made the label small and tried tapping then and it still wouldn't hit the breakpoint.

      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let row = indexPath.row

    selectedService = serviceArray[row].serviceID! as String

    if selectedService != "" {

      self.performSegue(withIdentifier: "fromCardDetailsToEditService", sender: self)

    }
  }

I do not know if it matters BUT...the VC that I am on is in a Tab Bar Controller and a Nav Bar Controller. Does it matter for the performSegue that I am in a Tab Bar? And that this button is not a tab bar item?

标签: swift swift3
2条回答
Melony?
2楼-- · 2019-06-03 15:49

I figured out how to have my Gesture Recognizer AND the didSelectRowAt.

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

This is what I already had, which was causing conflict.

To fix it, this simple line let me dismiss the keyboard AND be able to tap on my cells.

tap.cancelsTouchesInView = false
查看更多
Emotional °昔
3楼-- · 2019-06-03 16:04

Did you have any GestureRecognizer on your UIViewController because in case of GestureRecognizer tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) does not called.

查看更多
登录 后发表回答