Search code examples
ios5uitableviewstoryboardiboutlet

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


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


Solution

  • Actually,

    I have seen the video and they are not connecting the way you suggest. They are connecting from the cell to the UILabel in the cell. In other words, they have a subclass of UITableViewCell and are connecting those IBOutlets in the custom object. In its basic form, you can create a custom cell class and just declare the interface and synthesize the properties and you should be good to go. Just make sure you set up your identifier and custom class correctly in the storyboard.

    Hope this helps.