UITableView Class 参考 (1)<Creating Table View Cells>

Creating Table View Cells


  • – registerNib:forCellReuseIdentifier:
  • – registerClass:forCellReuseIdentifier:
  • – dequeueReusableCellWithIdentifier:forIndexPath:
  • – dequeueReusableCellWithIdentifier:

registerNib:forCellReuseIdentifier:


Registers a nib object containing a cell with the table view under a specified identifier.

- (void)registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)identifier

Parameters

nib

A nib object that specifies the nib file to use to create the cell. This parameter cannot be nil.

identifier

The reuse identifier for the cell. This parameter must not be nil and must not be an empty string.

Discussion

Prior to dequeueing any cells, call this method or the registerClass:forCellReuseIdentifier: method to tell the table view how to create new cells. If a cell of the specified type is not currently in a reuse queue, the table view uses the provided information to create a new cell object automatically.

If you previously registered a class or nib file with the same reuse identifier, the nib you specify in the nib parameter replaces the old entry. You may specify nil for nib if you want to unregister the nib from the specified reuse identifier.

详细说明:
在出列任何cell之前,调用这个方法或者 registerClass:forCellReuseIdentifier: 方法让tableview去创建新的cells。如果指定类型的cell不在当前可用的队列中,tableview使用提供的信息去自动创建新的cell对象。
如果你之前使用了相同的复用标示符去注册一个类或者nib文件,你在nib参数中指定的nib代替了旧的entry。如果你想从指定的可复用指示器中解除注册nib,你可以把nib设为nil.

dequeueReusableCellWithIdentifier:


Returns a reusable table-view cell object located by its identifier.

- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier

Parameters

identifier

A string identifying the cell object to be reused. This parameter must not be nil.

Return Value

A UITableViewCell object with the associated identifier or nil if no such object exists in the reusable-cell queue.

Discussion

For performance reasons, a table view'€™s data source should generally reuse UITableViewCell objects when it assigns cells to rows in its tableView:cellForRowAtIndexPath: method. A table view maintains a queue or list of UITableViewCell objects that the data source has marked for reuse. Call this method from your data source object when asked to provide a new cell for the table view. This method dequeues an existing cell if one is available or creates a new one using the class or nib file you previously registered. If no cell is available for reuse and you did not register a class or nib file, this method returns nil.

If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.

详细说明:

由于性能原因,在tableview 的tableView:cellForRowAtIndexPath:方法中,当它为每一行指定cell时,它的数据源应该复用UITableViewCell对象。table view保存了包含UITableViewCell对象的队列或者列表,这些UITableViewCell是数据源标记为复用的对象。当要求为table view提供新的cell时,从你的数据源对象中调用这个方法。如果已经存在一个可用的cell,那么这个方法会出列这个cell。如果不存在可用的cell,那么用你先前注册的类或者nib文件创建一个新的cell。如果没有可复用的cell并且你没有注册一个类或者 nib文件,那么这个方法返回nil。

如果你为指定的identifier注册一个类,并且一个新的cell必须被创建,这个方法通过调用 initWithStyle:reuseIdentifier:方法初始化cell。对于基于nib的cell,这个方法从提供的nib文件中加载cell对象,如果一个已经存在的cell可以复用,那么这个方法调用这个cell的prepareForReuse方法。


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值