Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewController's didSelectRowAtIndexPath doesn't work

I am using an UITableViewController for it and I override the following method and try to enable different segues when the user select different row.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("You selected row #\(indexPath.row)!")
    switch indexPath.row {
    case 3:
        performSegue(withIdentifier: "segue3", sender: self)
    case 8:
        performSegue(withIdentifier: "segue8", sender: self)
    default:
        break
    }
}

But actually, this method never get called, and the print out never show up when I select a row.

I did enable single selection, enable user interaction and set the delegate and datasource to the controller itself (That's automatically set when using UITableViewController, right?)

I am using static cells and default UITableViewCell. The view controller is UITableViewController.

enter image description here

Update:

I try to replace:

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

With:

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

And this doesn't work also.

like image 755
Patroclus Avatar asked Feb 19 '26 10:02

Patroclus


1 Answers

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 ...

like image 101
Foolish Avatar answered Feb 21 '26 15:02

Foolish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!