views:

101

answers:

1

Hi folks,

How do I customize the background image of a tableViewCell 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.

Thank you for your help! gstar

+2  A: 

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).

stefanB