
Untitled
By: a guest on
Jun 22nd, 2012 | syntax:
None | size: 1.49 KB | hits: 11 | expires: Never
iPad: Iterate over every cell in a UITableView?
for (int section = 0; section < [tableView numberOfSections]; section++) {
for (int row = 0; row < [tableView numberOfRowsInSection:section]; row++) {
NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell* cell = [tableView cellForRowAtIndexPath:cellPath];
//do stuff with 'cell'
}
}
for (UITableViewCell *cell in self.tableView.visibleCells) {
NSIndexPath *cellIndexPath = [self.tableView indexPathForCell:cell];
UITableViewCell *cell;
NSIndexPath indexPath = [[NSIndexPath indexPathForRow:0 inSection:0];
for(indexPath.section = 0; indexPath.section < [myTableView numberOfSections]; ++indexPath.section)
{
for(indexPath.row = 0; indexPath.row < [myTableView numberOfRowsInSection:indexPath.section]; ++indexPath.row)
{
cell = [myTableView cellForRowAtIndexPath:indexPath];
// do something with this cell
}
}
- (void)enumerateCellsUsingBlock:(void (^)(UITableViewCell *cell))cellBlock {
for (int section = 0; section < [self numberOfSections]; section++) {
for (int row = 0; row < [self numberOfRowsInSection:section]; row++) {
NSIndexPath *cellPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *cell = [self cellForRowAtIndexPath:cellPath];
cellBlock(cell);
}
}
}
[self.tableView enumerateCellsUsingBlock:^(UITableViewCell *cell) {
NSLog(@"cell:%@", cell);
}];