I have a TableView with 10 sections that are loaded from a plist file and I have switches with which some of the sections can be turned off. I need to set a specific background color for each section with the fact that the section can be disabled.
Example:
for section Black I need to set black background
for section Red I need to set red background
and so on…
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
tempHeaderView.backgroundColor=[UIColor blackColor];
[tempHeaderView addSubView: tempHeaderLabel];
return tempHeaderView;
}
Keep an
NSArrayofUIColorobjects as an instance variable of your class (the view controller that acts as delegate/data source), say you call itsectionColors. You can initialize the colors in this array from values in your plist, or hard-code the colors.Then, use this code:
This is how you could initialize the array:
(the code above should go inside the table view data source’s initializer)