Loading Custom Table-View Cells From Nib Files

帅比萌擦擦* 提交于 2019-12-02 00:12:39

问题


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

A Closer Look at Table-View Cells > Loading Custom Table-View Cells From Nib Files

Here

I am not sure about which class needs to be set..

7, Select File’s Owner in the nib document window, open the Identity pane of the inspector, and set the class of File’s Owner to your custom view controller class.


回答1:


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.



来源:https://stackoverflow.com/questions/7184206/loading-custom-table-view-cells-from-nib-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!