zoukankan      html  css  js  c++  java
  • dequeueReusableCellWithIdentifier

    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

  • 相关阅读:
    AptitudeSystem 2.0
    angularjs开发常见问题-2(angularjs内置过滤器)
    经常使用 Java API
    Spring Boot JPA 连接数据库
    机房收费系统个人重构版:软工文档中那些图
    Android
    Spring Boot 动态数据源(多数据源自己主动切换)
    java的nio包的SelectionKey,Selector,SelectableChannel三者的缠绵关系概述
    初探linux子系统集之timer子系统(三)
    mobiscroll 案例git
  • 原文地址:https://www.cnblogs.com/holyenzou/p/2511992.html
Copyright © 2011-2022 走看看