Reputation: 1113
I want to get the existing header views in a UITableView, so that I can update their appearances. I have been unable to find a method similar to visibleCells that would return the header views instead of cells. Is this possible, or should I just store these views during creation?
Upvotes: 0
Views: 78
Reputation: 2411
You should store them in an NSMutableArray. Here is some sample code:
@interface ViewController : UITableViewController (UITableViewDataSource, UITableViewDelegate)
@property (nonatomic, strong) NSMutableArray *sectionHeaderViews;
@end
@implementation ViewController
- (void)viewDidLoad {
self.sectionHeaderViews = [NSMutableArray array];
NSInteger numOfSections = [self numberOfSectionsInTableView:self.tableView];
for(int i=0; i<numOfSections)
{
CustomHeaderView *headerView = [[CustomHeaderView alloc] init];
// customize headerView here
...
[self.sectionHeaderViews addObject:headerView];
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [self.sectionHeaderViews objectAtIndex:section];
}
- (void)updateViewForSection:(NSInteger)section {
CustomHeaderView *headerView = [self.sectionHeaderViews objectAtIndex:section];
// update headerView here
...
// reload section
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation: UITableViewRowAnimationAutomatic];
}
@end
Good luck!
Upvotes: 1