Connect outlet of a Cell Prototype in a storyboard

前端 未结 3 1322
傲寒
傲寒 2020-12-02 07:32

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 Ce

3条回答
  •  攒了一身酷
    2020-12-02 08:18

    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.

提交回复
热议问题