从Nib文件加载自定义表格查看单元格 [英] Loading Custom Table-View Cells From Nib Files

查看:142
本文介绍了从Nib文件加载自定义表格查看单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在申请苹果文件中的一个例子,但我发现他们正在谈论的一些事情有点麻烦,特别是在

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查看表视图单元格>从Nib文件加载自定义表格查看单元格

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

这里

我不确定需要设置哪个类..

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


7,在nib文档窗口中选择文件的所有者,打开检查器的Identity
窗格,并将File的所有者类设置为
自定义视图控制器类。

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.


推荐答案

所有者是您的表视图控制器的实现。
在表视图控制器中定义UITableViewCell属性(在本例中为tvCell)

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;

然后在自定义表视图单元的nib文件中指定文件所有者,类型为MyTableViewController,将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.

然后在cellForRowAtIndex路径中,以下行:

Then in the cellForRowAtIndex path the following line:

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

此行加载单元格nib,将表视图控制器(即self)设置为所有者,因此连接表视图控制器中的tvCell属性以指向nib中的TableViewCell。

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.

然后,您可以获取该指针的副本并初始化单元格中的字段这个方法并从方法中返回'custom'单元格。

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.

这篇关于从Nib文件加载自定义表格查看单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆