alekseyn/EasyTableView — Issue #12: Sections
Author: BrandonCopley
Created: 2012-02-29 06:50:00+00:00
State: open

Alright why couldn't we implement headers and footers? I believe I have added headers and footers and done a great implementation.

Can I share this code?

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if ([delegate respondsToSelector:@selector(easyTableView:viewForHeaderInSection:)]) {
return [delegate easyTableView:self viewForHeaderInSection:section];
}
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

if ([delegate respondsToSelector:@selector(easyTableView:viewForFooterInSection:)]) {
return [delegate easyTableView:self viewForFooterInSection:section];
}
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

if ([delegate respondsToSelector:@selector(numberOfSectionsInEasyTableView::)]) {
return [delegate numberOfSectionsInEasyTableView:self];
}

return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSUInteger numOfItems = _numItems;

if ([delegate respondsToSelector:@selector(numberOfCellsForEasyTableView:inSection:)]) {
numOfItems = [delegate numberOfCellsForEasyTableView:self inSection:section];

// Animate any changes in the number of items
[tableView beginUpdates];
[tableView endUpdates];
}

return numOfItems;
}

- (UIView *)viewAtIndex:(NSUInteger)index inSection:(NSInteger)section{
NSIndexPath *indexPath	= [NSIndexPath indexPathForRow:index inSection:section];
UIView *cell	= [self.tableView cellForRowAtIndexPath:indexPath];

return [cell viewWithTag:CELL_CONTENT_TAG];
}

in the .h

- (NSUInteger)numberOfCellsForEasyTableView:(EasyTableView *)view inSection:(NSInteger)section;
- (NSUInteger)numberOfSectionsInEasyTableView:(EasyTableView*)easyTableView;
- (UIView*)easyTableView:(EasyTableView*)easyTableView viewForHeaderInSection:(NSInteger)section;
- (UIView*)easyTableView:(EasyTableView*)easyTableView viewForFooterInSection:(NSInteger)section;

- (UIView *)viewAtIndex:(NSUInteger)index inSection:(NSInteger)section;

This seems to work swimmingly.