DidSelectRowAtIndexPath. Not working

Did select Cell not working

Can someone tell me why this is not working please.

Hi @hcri50,
You have not set the delegate for the tableView to handler.

cheers,

Jayant

and if I may give you a suggestion, create a init function in Handler that lets you set the relevant stuff to tableView, like

class Handler : NSobject, UITableViewDataSource, UITableViewDelegate {

 init(withTable table: UITableView) {
  table.delegate = self 
  table.dataSource = self 
 }

// Setup all your other functions here
}

Now, you can call handler and be sure that everything is setup properly. In fact you can also add a data array and a cellType so that you can have a more useful re-usable class than what you have right now.

cheers,

Jayant

FIRST OF ALL, Thank you for your prompt reply. Sadly, I did copy and paste what you wrote and I am coming up with a NSObject Error. And I resolved the problem by setting the delegate this way.

class ViewController: UIViewController {
var handler: Handler!

@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
    super.viewDidLoad()
    
    handler = Handler()
    tableView.dataSource = handler
    tableView.delegate = handler
}

}
Now I got my didselectcell working.
THANK YOU AGAIN,
IF you are curious, download my code and add the code that you wrote and you will see why it did not work.

Hi @hcri50,
Glad it worked out for you. The error was the typo on my part, the code above reads NSobject, where as it should be NSObject - easy fix. However, if you got things working, that’s cool.

cheers,

Jayant

This topic was automatically closed after 166 days. New replies are no longer allowed.