Loading Custom Table-View Cells From Nib Files

前端 未结 1 899
臣服心动
臣服心动 2021-01-20 09:16

I am currently working though an example in the apple documents but am having a little trouble finding some of the things they are talking about, in particular inside

<
相关标签:
1条回答
  • 2021-01-20 10:03

    The owner is your implementation of the table view controller. In your table view controller you define a UITableViewCell property (in this case it is tvCell)

    @interface MyTableViewController: UITableViewController {
    
        IBOutlet UITableViewCell *tvCell;
    
        @property (nonatomic, retain) IBOutlet UITableViewCell *tvCell;
    

    Then in your nib file for the custom table view cell you specify the files owner as of type MyTableViewController and point the tvCell outlet to the table cell view in the nib.

    Then in the cellForRowAtIndex path the following line:

    [[NSBundle mainBundle] loadNibNamed:@"TVCell" owner:self options:nil];
    

    this line loads the cells nib, setting your table view controller (i.e. self) as the owner, thus connecting the tvCell property in your table view controller to point to the TableViewCell in the nib.

    You can then take a copy of that pointer and initialise the fields in the cell in this method and return that 'custom' cell from the method.

    0 讨论(0)
提交回复
热议问题