//
//  UITableView+HLTEnumarateCells.h
//
//  Created by Maciej Banasiewicz.
//

#import "UITableView+EnumarateCells.h"

@implementation UITableView (EnumarateCells)

- (void)enumarateTableViewCellsUsingBlock:(tableviewEnumerateHandler)handler
{
    BOOL stop = NO;
    for (int i = 0; i < self.numberOfSections; i++)
    {
        for (int j = 0; j < [self numberOfRowsInSection:i]; j++)
        {
            NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:j inSection:i];
            handler([self cellForRowAtIndexPath:newIndexPath], &stop);
            
            if (stop) {
                break;
            }
        }
        
        if (stop) {
            break;
        }
    }
}

- (void)enumarateTableViewCellsSection:(NSInteger)section UsingBlock:(tableviewEnumerateHandler)handler {

    BOOL stop = NO;
    for (int j = 0; j < [self numberOfRowsInSection:section]; j++)
    {
        NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:j inSection:section];
        handler([self cellForRowAtIndexPath:newIndexPath], &stop);
        
        if (stop) {
            break;
        }
    }
}

@end
