dequeueReusableCellWithIdentifier

from@"http://blog.youkuaiyun.com/dadalan/archive/2009/04/27/4129729.aspx"

 

 

dequeueReusableCellWithIdentifier:

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

- (UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier

Parameters
identifier

A string identifying the cell object to be reused. By default, a reusable cell’s identifier is its class name, but you can change it to any arbitrary value.

Return Value

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 reuseUITableViewCell objects when it assigns cells to rows in itstableView:cellForRowAtIndexPath: method. A table view maintains a queue or list ofUITableViewCell objects that the table view’s delegate has marked for reuse. It marks a cell for reuse by assigning it a reuse identifier when it creates it (that is, in theinitWithFrame:reuseIdentifier: method of UITableViewCell). The data source can access specific “template” cell objects in this queue by invoking thedequeueReusableCellWithIdentifier: method. You can access a cell’s reuse identifier through its reuseIdentifier property, which is defined by UITableViewCell.

Availability
  • Available in iPhone OS 2.0 and later.
Related Sample Code
Declared In

 

UITableView.h

 

 

 

dequeueReusableCellWithIdentifier的运行机制猜测

  1. static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
  2.     
  3.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#(NSString *)identifier#>]
  4.     
  5.     if (cell == nil) {
  6.         <#statements#>
  7.     }

书本上讲解的很随意,只是说为了重复使用,和节省资源的内部机制。
看文档介绍的也比较笼统,而代码也只是访问到头文件就终止了,所以才臆测一下实现的机制,还请高手们不论对于错都写点什么。其实我还是很疑惑的。

dequeueReusableCellWithIdentifier消息返回的是UITableViewCell对象,即是说这是一个用来获取UITableViewCell对象的消息,废话。
之所以不说是初始化一个对象,是因为它可能返回nil值,所以才要在下面补充一个如果cell为nil时的处理过程。
那么这个方法是不是可以解释成为,从一个UITableViewCell对象池中获取一个以Identifier参数命名的UITableViewCell对象。
如果在资源紧缺的时候,这个池会自动清理多余的UITableViewCell对象,则可能无法返回对象,但如果资源丰富,则会保存一些UITableViewCell对象,在需要调用的时候迅速的返回,而不用创建.

 

当TABLE一开始加载的时候。。REUSABLEQUEEE中没有任何元素。。当TABLE向下滚动时,滑出TABLEVIEW的CELL被加入到队列中。。下面用到相同的IDENTIFIER的CELL的时候就不用创建,直接 从QUEUE中拿出,修改相应的属性。。避免重复创建大量相同STYLE的CELL

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值