Reputation: 11
How do I customize the background image of a UITableViewCell
depending on the section, they are in? E.g. in section one, the cells are supposed to have a green .png image as a background image, whereas in section two, the cells are supposed to have a red .png image as background.
Upvotes: 1
Views: 312
Reputation: 119
example:
if(section == 0) {
background.image = [UIImage imageNamed:@"green.png"];
}
else if(section == 1) {
background.image = [UIImage imageNamed:@"blue.png"];
}
Upvotes: 0
Reputation: 79810
See Populating the Table View With Data for how to access and use section information.
When you have more then one section you implement some optional table view source methods to deal with sections.
Then when you create cell, check in which section it is and set it up accordingly, in:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
In this method you can access indexPath.section
and format your cell.
See Table View Programming Guide for more.
UIKit adds property section
to NSIndexPath
so you can get section
from index path passed in to the above method (see the first example I linked).
Upvotes: 2