开发者

UITableViewCell Loses Properties After Deselection

开发者 https://www.devze.com 2023-02-07 11:01 出处:网络
I have a custom subclass of UITableViewController that uses a set of custom subclass of UITableViewCells.

I have a custom subclass of UITableViewController that uses a set of custom subclass of UITableViewCells.

There is nothing too fancy. The table cell's have two subviews in their content view.

Right now I have the user select a cell, a navigation controller pushes to a color selection screen. The user selects a color. Great. The table view is a delegate of this view. It receives the color, updates the selected cell so that the subview now uses this background color, and then pops the current view from the navigation controller.

It all works! The tableViewController slides back into view and the indicator in the cell now displays the background color the user selected. BUT after the table view appears, the cell selected cell gets a blue highlight applied to it automatically. This is some built in magic from the TableViewController. It's nice but it's resetting my cell's indicator status.

Problem is, I can't find out where to properly update the cell to this new color. The color is stored as an ivar in the tableViewController. So I thought 开发者_开发百科trying this out at:

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

But alas this method doesn't fire as a result of the magic UIKit is doing to briefly highlight the cell. Any ideas where I need to update my cell properly?


I'm not sure how you are setting the background color yet, but you should be using the backgroundView property of your UITableViewCell subclass.

someCell.backgroundView.backgroundColor = someColor;

(from inside your UITableViewController, or wherever you are getting that color information back from your picker).

Doing this should not reset the background color when the cell goes from selected to deselected.

0

精彩评论

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