Last active
December 11, 2015 21:28
-
-
Save modamoda/4662395 to your computer and use it in GitHub Desktop.
UITableView: traversing all index paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [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