Didselectrowatindexpath Not Working, Swift 3

didSelectRowAtIndexPath not working, Swift 3

Swift 3 modified the signature of the method (a lot of methods too, new "rules"/style)

Replace:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) with

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

Notice the _, the didSelectRowAt vs didSelectRowAtIndexPath, like the other ones you updated (which adapted also the same "style"), but not this one.

Remove the line and let XCode do the autocompletion. Else, you can just replace it with the one from the doc.

Swift UITableView didSelectRowAtIndexPath not getting called

You have to set an @IBOutlet to the tableView in you ViewController and set as it's delegate and dataSource to you can see the data an respond to changes in the tableView.

Something like this :

override func viewDidLoad() {
super.viewDidLoad()

self.tableView.delegate = self
self.tableView.dataSource = self
}

And implements the UITableViewDataSource protocol too.

Or you can too in the Interface Builder set the ViewController as it's delegate and dataSource (more easy to do I think) and avoid to set manually in code like above. Is up to you.

I hope this help you.

UITableViewController's didSelectRowAtIndexPath doesn't work

for Swift 3

override  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
// your code ...
}

and one thing make sure your tableView single selection property is selected ...

-didSelectRowAtIndexPath: not being called

It sounds like perhaps the class is not the UITableViewDelegate for that table view, though UITableViewController is supposed to set that automatically.

Any chance you reset the delegate to some other class?

My didSelectRowAtIndexPath not called

Cross verify the following things at it prevents the didSelectMethod to work:

  1. Is the userInteraction not disabled for tableView
  2. Have not given any tap gesture to the main UIView i.e like for example

        // Tap Gesture
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(HomeVC.tapBlurButton(_:)))
    self.view.addGestureRecognizer(tapGesture)

and use it like

 @objc func tapBlurButton(_ sender: UITapGestureRecognizer) {
tblZoneType.reloadData()
}

This will prevent the interaction with the tableView (Personally experienced the problem, and my didSelect was not called) and i removed the code of tap gesture and it worked back


  1. Have given the dataSource and delegates correctly.
  2. Does not have any View covering the tableView.

Hope this helps.

DidSelectRowAtIndexPath not being called at all

I pulled your code into XCode (in a blank project).

I commented out all the lines that didn't have to do with the tableView.

I dropped a tableView into the view controller, assigned the delegate and datasource gave the prototype cell the identifier of "cell" and it works, meaning the tableview is drawn, and when I select a row, it fires the didSelectRowAtIndexPath.

You sent gave a screenshot of the viewController outlets, but the problem is probably in the tableView outlets. Remove them all and add only dataSource and delegate back (for debugging purposes)

Also, the code in cellForRowAtIndexPath and didSelect... you are assigning values to items it doesn't have a reference to (assuming you are using the prototype UITableViewCell and not a custom cell?) For testing, I would comment out everything in cellForRow... except dequeueing the cell, and returning the cell, and in the didSelect.... just leave print("foo") for now.

Also, I just gave autoComplete a value of 5 records to I would have 5 rows. I'm assuming you are getting rows, so the autocomplete is not the issue.

Let me know if this helps. Happy to help further if needed.



Related Topics



Leave a reply



Submit