Skip to content

Instantly share code, notes, and snippets.

@modamoda
Last active December 11, 2015 21:28
Show Gist options
  • Save modamoda/4662395 to your computer and use it in GitHub Desktop.
Save modamoda/4662395 to your computer and use it in GitHub Desktop.
UITableView: traversing all index paths
// [self.tableView eachIndexPath^(NSIndexPath *indexpath) { ... }];
@interface UITableView (Traverse)
typedef void (^iter)(NSIndexPath *indexPath);
- (void)eachIndexPath:(iter)iterBlock;
@end
@implementation UITableView (Traverse)
- (void)eachIndexPath:(iter)iterBlock
{
if (iterBlock != NULL) {
NSInteger sectionCount = [self numberOfSections];
for (NSInteger section = 0; section < sectionCount; section++) {
NSInteger rowCount = [self numberOfRowsInSection:section];
for (NSInteger row = 0; row < rowCount; row++) {
iterBlock([NSIndexPath indexPathForRow:row inSection:section]);
}
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment