Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 540
Tobias Bambullis Avatar asked Nov 02 '11 23:11

Tobias Bambullis


2 Answers

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.)

like image 101
Symmetric Avatar answered Sep 23 '22 08:09

Symmetric


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.

like image 33
Jamie Avatar answered Sep 22 '22 08:09

Jamie