Brendon Cheung Brendon Cheung - 5 months ago 54
Swift Question

didSelectCellAtIndexPath not called

I know there are a lot of relevant post on this and I have tried all of the ones I can find and unfortunately the problem still persists.

So I have a

inside of an
which is populated by 2 custom cells, one has got an
and the other one got an
, and both have a
. I then proceeded to implement the
didSelectCell(at: IndexPath)

I made sure the delegate is hooked up to the view controller.

Inside of the method, I simply wrote a print statement to ensure the taps are registering. However, the print message did to get printed to the console when I tapped on the
and on the

I have a feeling it is something to do with the
thing with the
, and it is eating away my tap registration, but not really sure.

Any feedbacks are welcome!


Here is the setup on my custom cell:

enter image description here

Here is the

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

print("tapped on cell")

if let cell = tableView.cellForRow(at: indexPath) as? NumericInputTableViewCell{
print("Tapped on numericcell")
} else if let cell = tableView.cellForRow(at: indexPath) as? BooleanInputTableViewCell {
print("Tapped on booleancell")


Answer Source

The delegate method is triggered when you click on the cell, not other elements on the cell. So create some empty cell in your table view and have another try. If it get printed out then that means you have elements covered over the cell and the cell itself is not clicked.

You can then disable user interaction for your UITextField stuffs from storyboard and then have a try. Ideally, when you click on the textfield on a table view cell, the correct respond I am thinking is that keyboard will show up and didSelectCell should not be triggered.

Here is the demo

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download