美文网首页
认识 - dequeueReusableCellWithIden

认识 - dequeueReusableCellWithIden

作者: 梅西和他的世界杯 | 来源:发表于2016-01-17 15:54 被阅读1916次

标签: iOS,苹果开发文档


- dequeueReusableCellWithIdentifier:forIndexPath:
Returns a reusable table-view cell object for the specified reuse identifier and adds it to the table.

Declaration

SWIFT
func dequeueReusableCellWithIdentifier(_ identifier: String,
                          forIndexPath indexPath: NSIndexPath) -> UITableViewCell
OBJECTIVE-C
- (__kindofUITableViewCell * _Nonnull)dequeueReusableCellWithIdentifier:(NSString * _Nonnull)identifier
                                                           forIndexPath:(NSIndexPath * _Nonnull)indexPath           ```
                                                           
## **Parameters**
> **identifier**    
A string identifying the cell object to be reused. This parameter must not be nil.
> **indexPath** 
The index path specifying the location of the cell. The data source receives this information when it is asked for the cell and should just pass it along. This method uses the index path to perform additional configuration based on the cell’s position in the table view.
指定cell位置的索引路径。当它被调用时,数据源收到这个消息,应该让他通过。这个方法以cell在tableView中的位置使用索引路径去执行附加的配置。

> **Return Value**
A UITableViewCell object with the associated reuse identifier. This method always returns a valid cell. 
返回一个有重用标志的tableViewCell对象。这个方法总是返回一个有效的cell。

## **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 based on the class or nib file you previously registered, and adds it to the table.

> 出于性能的原因,一个TableView的数据源一般应该重用tableViewCell对象,当它被分配到每一行的时候。一个TableView保持一个tableViewCell队列或者列表给数据源重用。当被要求提供一个新的cell给TableView,调用这个方法从你的数据源拿到对象。如果有一个可用的cell, 这个方法出队列一个存在的cell,或者基于你以前注册的一个类或者nib文件创建一个新的,并把它添加到table中。

**IMPORTANT**
You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method. 
> 也就是使用这个方法前,一定要注册cell

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. 

如果你注册了一个指定标识符并且一个新的cell一定被创建的类,这个方法初始化cell会调用 initWithStyle:reuseIdentifier:方法。对于基于nib的cell,这个方法会加载cell对象从提供的nib文件中。如果一个存在的cell是可以被重用的,这个方法会调用cell’s prepareForReuse方法。

## **Availability**
Available in iOS 6.0 and later.




相关文章

  • 认识 - dequeueReusableCellWithIden

    标签: iOS,苹果开发文档 - dequeueReusableCellWithIdentifier:forInd...

  • Tips:dequeueReusableCellWithIden

    dequeueReusableCellWithIdentifier:forIndexPath: 官方解释是 iOS...

  • 认识“认识”

    以前说的两个人是否认识,是指两个人或有接触或有交往,至少有过一面之缘算是认识的,否则,那就是...

  • 认识认识

    兔兔图图

  • 认识你,认识温暖 —— 认识大晶

    一路走来,我们遇见很多人。一路走去,更多的人与我们走散。但总有一些温暖,遇见就留下,任何时候想起,都在心间。 01...

  • 要不,和我认识认识。

    文/余忆初 哈喽,大家好啊,我叫余忆初呀。 98年出生,大三女。目前就读于武汉。 水瓶座,极其敏感而又偏于乐观。 ...

  • 认识自己 认识人生

    我要如何度过此生?

  • 认识自己认识世界

    事物的两面性 羊群效应有利有弊,不能一概而论,主要看初始行动方向,既会加速积极影响,方向错误也会加速消极影响。 认...

  • 认识世界,认识自己

    今天我从认知的方式开始说起,认识世界、认识自己。 聊一聊我所理解的 知识 与 智慧,以及人的 外倾 与 内倾。 对...

  • 认识你自己?认识。

    这是我参加弗兰克老师动手返现特训营后的第7次作业,每一次写作业,就仿佛在经历全新的一天,在慢慢认识我自己。...

网友评论

      本文标题:认识 - dequeueReusableCellWithIden

      本文链接:https://www.haomeiwen.com/subject/dgqkkttx.html