Reputation: 275
I have added this function so that I can select a cell in table view:
extension Home: UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Row #: \(indexPath)")
segway()
}
}
However, nothing happens (no print or segway to another view controller) except a highlighted cell.
Few things I've tried:
1) I have found online that the tap gesture recognizer can interfere with this, so I removed this even though it was from a separate class. This had no effect.
2) I made sure the attributes inspector "Selection" was set to "Single Selection"
Something to note:
I have programatically set up the table view to receive its data from core data fetch request, after saving to core data from an alert controller, which was called from an IBAction button (button pressed -> alert controller -> write string -> save string -> fetch string -> reload table view with new data/strings).
Upvotes: 1
Views: 2169
Reputation: 275
I figured it out. I needed to add:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.allowsSelection = true
self.tableView.delegate = self
}
Upvotes: 1
Reputation: 243
Check your tableView's delegate property to verify that it is set to the instance you are expecting the didSelectRowAt function to be called.
Upvotes: 1