dequeueReusableCellWithIdentifier:forIndexPath:的indexPath在哪里使用? [英] Where does the indexPath of dequeueReusableCellWithIdentifier:forIndexPath: get used?
问题描述
Apple的文档说明 indexPath
参数:
Apple's documentation says of the indexPath
parameter:
索引路径指定细胞的位置。数据源在被要求提供单元格时会收到此信息,并且应该将其传递给它。此方法使用索引路径根据单元格在表视图中的位置执行其他配置。
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.
但 register(Class | Nib):forCellReuseIdentifier:
仅指定要使用的重用标识符,而不是段或一组索引路径。
But register(Class|Nib):forCellReuseIdentifier:
only specifies the reuse identifier to use, not the section or a set of index paths.
I想也许 UITableViewCell
有一些方法可以把它放在索引路径上,所以如果在一个部分的第一行,它可以绕过它的角,但我是没有看到它。在创建时,它获得的只是它的样式和重用标识符( initWithStyle:reuseIdentifier:
);在重用时,所有它被告知是 prepareForReuse
。
I thought perhaps UITableViewCell
had some way of getting its hands on the index path, so it could, say, round its corners if in the first row of a section, but I'm not seeing it. At creation time, all it gets is its style and reuse identifier (initWithStyle:reuseIdentifier:
); at reuse time, all it gets told is prepareForReuse
.
看作旧的 dequeueReusableCellWithIdentifier :
仍然受支持,如果它不能依赖有机会这样做,它可能会采用哪种基于索引路径的配置?
Seeing as the old dequeueReusableCellWithIdentifier:
is still supported, what sort of index-path-based configuration could it possibly be doing, if it can't rely on having the chance to do it, anyway?
我检查了表视图编程指南,但是自iOS 5以来它没有更新。
I checked the Table View Programming Guide, but it hasn't been updated since iOS 5.
推荐答案
根据 WWDC 2012会议200 - Cocoa Touch中的新功能,
如果您使用 - dequeueReusableCellWithIdentifier:forIndexPath :
要将您的单元格出列,它将是正确的大小,您可以在单元格的 contentView $ c $中进行布局
c>。
If you use - dequeueReusableCellWithIdentifier:forIndexPath:
to dequeue your cell, it will be the right size and you'll be able to do layout inside your cell's contentView
.
这几乎是来自UIKit工程师Chris Parker的引用。
That's pretty much a quote from Chris Parker, a UIKit Engineer.
直到iOS 6 ,你必须继承你的 UITableViewCell
并覆盖 - layoutSubviews
如果你想进行布局调整。从封装的角度来看,这可能仍然是更好的解决方案 - 但是,有时你只需要一个微小的调整,现在你可以在 - tableView:cellForRowAtIndexPath:
中代替。
Up until iOS 6, you had to subclass your UITableViewCell
and override - layoutSubviews
if you wanted to make layout adjustments. From encapsulation point of view, this might still be the better solution – however, sometimes you just need a tiny adjustment, and now you can do that in - tableView:cellForRowAtIndexPath:
instead.
这篇关于dequeueReusableCellWithIdentifier:forIndexPath:的indexPath在哪里使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!