標(biāo)簽: iOS汰扭,蘋果開發(fā)文檔
- 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位置的索引路徑驾荣。當(dāng)它被調(diào)用時(shí)檐蚜,數(shù)據(jù)源收到這個(gè)消息,應(yīng)該讓他通過(guò)如孝。這個(gè)方法以cell在tableView中的位置使用索引路徑去執(zhí)行附加的配置项贺。
> **Return Value**
A UITableViewCell object with the associated reuse identifier. This method always returns a valid cell.
返回一個(gè)有重用標(biāo)志的tableViewCell對(duì)象褂策。這個(gè)方法總是返回一個(gè)有效的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.
> 出于性能的原因折联,一個(gè)TableView的數(shù)據(jù)源一般應(yīng)該重用tableViewCell對(duì)象粒褒,當(dāng)它被分配到每一行的時(shí)候。一個(gè)TableView保持一個(gè)tableViewCell隊(duì)列或者列表給數(shù)據(jù)源重用诚镰。當(dāng)被要求提供一個(gè)新的cell給TableView奕坟,調(diào)用這個(gè)方法從你的數(shù)據(jù)源拿到對(duì)象。如果有一個(gè)可用的cell, 這個(gè)方法出隊(duì)列一個(gè)存在的cell,或者基于你以前注冊(cè)的一個(gè)類或者nib文件創(chuàng)建一個(gè)新的清笨,并把它添加到table中月杉。
**IMPORTANT**
You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.
> 也就是使用這個(gè)方法前,一定要注冊(cè)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.
如果你注冊(cè)了一個(gè)指定標(biāo)識(shí)符并且一個(gè)新的cell一定被創(chuàng)建的類抠艾,這個(gè)方法初始化cell會(huì)調(diào)用 initWithStyle:reuseIdentifier:方法苛萎。對(duì)于基于nib的cell,這個(gè)方法會(huì)加載cell對(duì)象從提供的nib文件中。如果一個(gè)存在的cell是可以被重用的检号,這個(gè)方法會(huì)調(diào)用cell’s prepareForReuse方法腌歉。
## **Availability**
Available in iOS 6.0 and later.