- (NSArray *)allCells
{
NSMutableArray *cells = [NSMutableArray array];
NSInteger i, j;
NSInteger sections = [self numberOfSections];
for (i = 0; i < sections; i++)
{
NSInteger rows = [self numberOfRowsInSection:i];
for (j = 0; j < rows; j++)
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
UITableViewCell *cell = [self cellForRowAtIndexPath:indexPath];
[cells addObject:cell];
}
}
return cells;
}
Hmmm.. I never heard about categories..
And thanks for the code!
@interface UITableView (DLAdditions)
- (NSArray *)allCells;
@end
@implementation UITableView (DLAdditions)
- (NSArray *)allCells
{
...
}
@end
- (NSArray *)allCells
- (NSArray *)NBS_allCells
One small tip is to prefix all of your category methods. For example:
Code:- (NSArray *)allCells
becomes:
Code:- (NSArray *)NBS_allCells
The reason is that if Apple decides to implement their own allCells method in a future version of the OS, wacky things can happen. You want to prefix your methods with a unique string (your name or your company) that you know Apple won't be using for their own work.
I am not sure the code in post #2 would work. There is this comment in UITableView.h near the cellForRowAtIndexPath:
// returns nil if cell is not visible or index path is out of range
Maybe you should check it in real project (and even that wouldn't prove anything in the light of the remark from the header file).