7

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?

4

2 回答 2

13

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.

于 2013-08-07T22:46:31.853 回答
3

The elegant solution is to use your table view's delegate method tableView:didSelectRowAtIndexPath: and put all your action code there.

于 2013-08-07T22:44:44.897 回答