Where does the indexPath of dequeueReusableCellWithIdentifier:forIndexPath: get used?
ios, ios6, uitableview
Solution
According to WWDC 2012 Session 200 - What's New In Cocoa Touch,
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`.
That's pretty much a quote from Chris Parker, a UIKit Engineer.
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.
Problem
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. But `register(Class|Nib):forCellReuseIdentifier:` only specifies the reuse identifier to use, not the section or a set of index paths. 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`. 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? I checked the Table View Programming Guide, but it hasn't been updated since iOS 5.