1

I have made a custom xib UITableViewCell with a UIButton inside. The contentView within the cell has, and must have .isUserInteractionEnabled = True. The problem I am facing is that when using

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("selected row at index: \(indexPath)")
 }

of UITableView the function does not get called. I have read that for some reason I cannot have didSelectRowAt working while contentView.isUserInteractionEnabled = True. It's either one or the other type of deal. However, in my situation, I must have contentView.isUserInteractionEnabled = True and didSelectRowAt working. So what is a good workaround for this problem?

I already have :

tableView.dataSource = self
tableView.delegate = self
dre_84w934
  • 678
  • 8
  • 27
  • I Assume that your UITableViewCell's isUserInteractionEnabled = false or you are tap the button. – Lenin Mar 25 '18 at 02:10
  • it's not clear what you are trying to achieve. If you enable the user interaction, the content view becomes the first responder, and, if that same content view can handle the tap, didSelect will not be executed. But if you only need the button, then you should not need to enable user integration on the whole content view. Can you explain in more detail what you are doing? – Gi0R Mar 25 '18 at 05:13
  • @GiorgioR. I need the user interaction enabled because I have a scroll view inside the cell. The scroll view slides another view to unveil the delete cell button. However, to your comment, none of the objects on my cell print out as first responders, when isUserInteractionEnabled=true. – dre_84w934 Mar 25 '18 at 08:52
  • @Lenin yes, didSelectRowAt only works when isUserInteractionEnabled = true for contentView, when false, it did not work – dre_84w934 Mar 25 '18 at 08:55

0 Answers0