views:

18

answers:

1

Hello, guys.

I have a table view with 9 rows at minimum. The background colors of the cells will depend of the cell position. If it is bellow to 3 or below to 6 or below to 9, the background color changes (see the next image).

alt text

The problem is that this table view can be reordered and I have to maintain the same color pattern. Example: if i change the 4th row to the 3th position, its background color must change from yellow to red.

To get the different colors, I used the method - (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath, but this method is called only when the cell will be displayed and isn't good for reordering issues (the cell is already displayed and the color don't change).

I already tried to create a method to change the background color that is called just after the row was moved, but the color didn't changed (it seems that changing the background color with cell.backgroundColor property just works in - (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath). :(

Any ideas how I can do that?

Thanks in advance.

+1  A: 

Adjust the position in your data source however you are doing, then tell your data source to recalculate the colours for each item based on their current position. Then reload your table view. It should "just work".

jer