Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect outlet of a Cell Prototype in a storyboard

I'm a newbie with the Storyboard and so I have some difficulties...

I have created a TableViewController and I would like to customize the Cell Prototype. In the Cell Prototype I have added several Labels I would like to customize with my own class which inherits from UITableViewCell (AreaListCell). In the Storyboard, for the Cell Prototype I have configured the Custom Class with "AreaListCell" and its style is "Custom".

In the storyboard, when I select the Cell Prototype and then the assistant, the assistant display my class that implements the UITableViewController (AreasTableViewController) and not
my "AreaListCell" class.

The consequence is I can create outlet (using Ctrl + Drag from the label of the Cell Prototype) to the AreasTableViewController class but not to the AreaListCell class ! Any idea how to connect the Cell Prototype with my AreaListCell class?

Thanks for your help!

like image 462
sebastien Avatar asked Apr 16 '12 14:04

sebastien


People also ask

What is prototype cell?

A prototype cell acts a template for your cell's appearance. It includes the views you want to display and their arrangement within the content area of the cell. At runtime, the table's data source object creates actual cells from the prototypes and configures them with your app's data.


1 Answers

UPDATE: As of Xcode 4.6 (possibly earlier) you can now create outlets by control-dragging! - This has to be done into an interface section or class extension (the class extension doesn't exist by default for new cell subclasses. Thanks to Steve Haley for pointing this out.

You can't get the outlet automatically connected and created by dragging into the code block in the assistant editor, which is poor, but you can create the outlets manually and connect them then.

In your cell subclass interface:

@interface CustomCell : UITableViewCell  @property (nonatomic) IBOutlet UILabel* customLabel;  @end 

Synthesize as normal in the implementation.

In the storyboard, select the cell and go to the connections inspector, you will see the new outlet. Drag from there to the relevant element in your prototype:

enter image description here

This can now be accessed as cell.customLabel in your cellForRowAtIndexPath: method.

like image 148
jrturton Avatar answered Oct 14 '22 06:10

jrturton