Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an action to a custom UITableViewCell

I am building a simple app with a table view filled with custom view cells and using a storyboard. I want to add a actions on the cell each time the user tap it.

So far, I tried to create an IBOutle to link my cell to my tableViewController and add the action manually in the code but each time I try to do it I get an error message saying "Illegal Configuration - cannot have a prototype object as its destination".

The only quick fix I found is to add a UIButton with a transparent background and no title which fills in the whole cell and attached the action to it.

Is there any more elegant way to do it?

like image 716
Spearfisher Avatar asked Aug 07 '13 22:08

Spearfisher


1 Answers

Not only is there a more "elegant" solution, but there is also a correct way to do this.You should be using the didSelectRowAtIndexPath method for your cells.

You should read what the Apple Docs have to say

And also, here is a tutorial on how to use row selection in your tableView.

like image 123
CaptJak Avatar answered Oct 05 '22 23:10

CaptJak