Reputation: 4496
I am using an UIButton to show and toggle a table-cell-item from read to unread. I used a blue image as a background to show when an item was unread, and that worked, but figured that it would be better to use the setHighlighted feature, as it saves adding an extra image to the App. The code I use is as follows:
- (void)updateReadButton{
if(article.read.boolValue){
//[readButton setBackgroundImage:nil forState:UIControlStateNormal];
[readButton setHighlighted:FALSE];
[readButton setNeedsLayout];
} else {
[readButton setHighlighted:TRUE];
[readButton setNeedsLayout];
}
}
This works fine for the initial creation of the cell. But when the item is clicked and the detail-view is shown I toggle the 'read' value to 'true' and change the setHighlighted option to false of the UIButton in the cell, but it doesn't change when coming back from the detail view. Only when the cell is scrolling off the screen and recreated is the change reflected. How can I force a redraw of the button once I navigate to the detail view?
Upvotes: 0
Views: 2304
Reputation: 953
You may be able to accomplish the highlight by simply reloading the cell in question. Peek at UITableView's - (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
and use it to reload the cell after setting the highlight.
Upvotes: 1
Reputation: 18741
I don't think the method setHighlighted:
is the correct one. Here is the documentation:
Specify YES if the control is highlighted; otherwise NO.
By default, a control is not highlighted. UIControl automatically sets and clears this state automatically when a touch enters and exits during tracking and when there is a touch up.
Upvotes: 1