Reputation: 422
I have an UITableViewController with some static cells embedded into an UIViewController using a container view. Within this UITableViewController I need the possibility to toggle the visibility of a cell containing an UIPickerView. I tried the following within my TableViewController to detect a tap on the cell but it didn't print anything:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath: NSIndexPath) {
print("Tap detected.", didSelectRowAtIndexPath)
}
I also tried working with reuse identifiers but it returned null at every cell.
Can you tell me how to detect a tap on a cell within the TableViewController? Complete code attached.
Upvotes: 2
Views: 199
Reputation: 324
I checked your code and saw that you are adding a tap gesture recognizer to the whole view. It might be that this stops touches from being transferred to the tableview cells. I would try removing that gesture recognizer and then try again if you reach the didSelect function when clicking the cells.
Upvotes: 1
Reputation: 422
If you setted correctly the delegate and datasource of tableView, you should change the function to the following and see if you actually print the row:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Tap detected. Selected indexPath is: \(indexPath.row)")
}
Upvotes: 1
Reputation: 5039
Try to update your viewDidLoad method as follows
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
Upvotes: 1