开发者

How to change the background color of a table view cell after it was moved?

开发者 https://www.devze.com 2023-01-13 14:22 出处:网络
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

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

How to change the background color of a table view cell after it was moved?

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*)indexPat开发者_Go百科h, 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消