How to connect an IBOutlet from an UITableViewController directly to custom cell?

Tobias Bambullis picture Tobias Bambullis · Nov 3, 2011 · Viewed 9.6k times · Source

A few days ago, I watched the video tutorial which explains how to use custom cells in an UITableViewController. I've learned that I can prepare a custom cell directly in the interface builder, so I did following:

I created a UITableViewController and connect a custom class which consists of an IBOutlet (UILabel). After that, I switched in my storyboard and prepared my custom cell with an UILabel. Finally I connect the label from UITableViewController to my custom cell directly.

The following happens:

Couldn't compile connection: <IBCocoaTouchOutletConnection:0x400724860  <IBProxyObject: 0x4007872c0> => productLabel => <IBUIImageView: 0x401080220>>

Isn't it possible to connect this directly? In the tutorial video of WWDC 2011 Section (Session #309) they do exactly what I did. But there is a hook: they don't show the code behind, they just connect it like I explained above.

For a better understanding I add a screenshot which shows, what i connect: enter image description here

Answer

Symmetric picture Symmetric · Feb 12, 2012

I had what turned out to be the same problem in this question. As the answerer of my question said, the problem is that the cell here is a prototype cell. A connection between a cell element and UITableViewController works fine for a table view with static cells since they are created at launch, but it doesn't make sense for prototype cells since many of them will probably be created...and they don't exist until cellForRowAtIndexPath is called. (This is a really poor error message, and Xcode probably shouldn't let you make a illegal connection like this.)