dequeueReusableCellWithIdentifier
来源:互联网 发布:杭州饭店 知乎 编辑:程序博客网 时间:2024/04/19 08:56
from@"http://blog.csdn.net/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
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 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
- DrillDownSave
- SimpleDrillDown
- TableSearch
- TableViewSuite
- UICatalog
Declared In
UITableView.h
dequeueReusableCellWithIdentifier的运行机制猜测
- static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#(NSString *)identifier#>]
- if (cell == nil) {
- <#statements#>
- }
书本上讲解的很随意,只是说为了重复使用,和节省资源的内部机制。
看文档介绍的也比较笼统,而代码也只是访问到头文件就终止了,所以才臆测一下实现的机制,还请高手们不论对于错都写点什么。其实我还是很疑惑的。
dequeueReusableCellWithIdentifier消息返回的是UITableViewCell对象,即是说这是一个用来获取UITableViewCell对象的消息,废话。
之所以不说是初始化一个对象,是因为它可能返回nil值,所以才要在下面补充一个如果cell为nil时的处理过程。
那么这个方法是不是可以解释成为,从一个UITableViewCell对象池中获取一个以Identifier参数命名的UITableViewCell对象。
如果在资源紧缺的时候,这个池会自动清理多余的UITableViewCell对象,则可能无法返回对象,但如果资源丰富,则会保存一些UITableViewCell对象,在需要调用的时候迅速的返回,而不用创建.
当TABLE一开始加载的时候。。REUSABLEQUEEE中没有任何元素。。当TABLE向下滚动时,滑出TABLEVIEW的CELL被加入到队列中。。下面用到相同的IDENTIFIER的CELL的时候就不用创建,直接 从QUEUE中拿出,修改相应的属性。。避免重复创建大量相同STYLE的CELL
- dequeueReusableCellWithIdentifier
- dequeueReusableCellWithIdentifier
- dequeueReusableCellWithIdentifier
- dequeueReusableCellWithIdentifier
- dequeueReusableCellWithIdentifier vs dequeueReusableCellWithIdentifier : forIndexPath
- dequeueReusableCellWithIdentifier:CellIdentifier
- UITableView dequeueReusableCellWithIdentifier
- 区别dequeueReusableCellWithIdentifier 和dequeueReusableCellWithIdentifier: forIndexPath
- dequeueReusableCellWithIdentifier和dequeueReusableCellWithIdentifier:forIndexPath的区别
- dequeueReusableCellWithIdentifier: 与dequeueReusableCellWithIdentifier: forIndexPath:的区别
- dequeueReusableCellWithIdentifier:和dequeueReusableCellWithIdentifier: forIndexPath:的问题
- [tableView dequeueReusableCellWithIdentifier:@"identify"]
- dequeueReusableCellWithIdentifier的运行机制
- dequeueReusableCellWithIdentifier的理解
- dequeueReusableCellWithIdentifier方法问题
- dequeueReusableCellWithIdentifier的运行机制
- dequeueReusableCellWithIdentifier的理解
- dequeueReusableCellWithIdentifier: forIndexPath: 获取cell
- IE 不重新发送信息 无法刷新网页 重试 讨厌窗体的解决
- cvs 配置
- 中国人 注意了!!必看!!!!
- 据黄宏生演讲编写【5点体会 提升人生】
- 监控SQL Server2005与sql 2008数据库的运行状况
- dequeueReusableCellWithIdentifier
- 物理文件碎片整理
- 附近的说法
- 一种解决无法显示Wikipedia图片的方法
- 可重入与异步信号安全
- proxool连接池配置详细说明
- 制作SSIS Package包图解全过程续c#调用SSIS Package把SQL数据导入到Excel文件
- Struts2解决表单重复提交
- 交通银行取款记