Rightpoint / RZCellSizeManager

Dynamic size computation and caching for cells.
MIT License
242 stars 32 forks source link

Index Path #21

Open jadar opened 10 years ago

jadar commented 10 years ago

Is there a way to get the index path of the cell I'm currently configuring? My configuration code relies on the index path in part of it. I already tried [tableView indexPathForCell:cell] and that returned nil.

ndonald2 commented 10 years ago

You can ask the tableview for the index path for the cell:

__weak typeof(self) weakSelf = self;
[self.sizeManager registerCellClassName:NSStringFromClass([TableViewCell class]) 
                           withNibNamed:nil 
                         forObjectClass:[CellData class] 
                     configurationBlock:^(TableViewCell *cell, CellData *object) {
                         NSIndexPath *indexPath = [weakSelf.tableView indexPathForCell:cell];
                         // ... do something with index path ...
                     }];
jadar commented 10 years ago

Yes but that returns nil. I assume because the cell has not yet been added to the table view due to the height being called before the cell is added. Or do I have the order of things wrong?

ndonald2 commented 10 years ago

Nope, you're totally right, that was my oversight. If you'd like to add the index path to the block signatures, please do so and open a pull request. That would be a welcome enhancement.

jadar commented 10 years ago

I'd be happy to. Should I just add an extra block signature or change the current one?

ndonald2 commented 10 years ago

Hmm. I'd say change the current one, but then it will not be backwards compatible. But that's much better than having duplicate signatures for everything so go ahead and change it. We can release it as a major version update.

Thanks!