user2640633
user2640633

Reputation:

Swift DidSelectRowAt not firing

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?

Upvotes: 2

Views: 819

Answers (2)

user2640633
user2640633

Reputation:

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

Upvotes: 5

Usman Javed
Usman Javed

Reputation: 2455

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

Upvotes: 6

Related Questions