UISearchBar があります。セルを選択すると、セル全体に [UIColor grayColor] が必要です。
以下のコードでは、contentView の色がグレーに表示されます。ただし、背景の accessoriesType の色は青色で表示されます。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.searchDisplayController.searchResultsTableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor grayColor];
if (self.lastSelected && (self.lastSelected.row == indexPath.row))
{
cell.accessoryType = UITableViewCellAccessoryNone;
[cell setSelected:NO animated:TRUE];
self.lastSelected = nil;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.accessoryView.backgroundColor = [UIColor grayColor]; // Not working
[cell setSelected:TRUE animated:TRUE];
UITableViewCell *old = [self.searchDisplayController.searchResultsTableView cellForRowAtIndexPath:self.lastSelected];
old.accessoryType = UITableViewCellAccessoryNone;
[old setSelected:NO animated:TRUE];
self.lastSelected = indexPath;
}
青を[UIColor grayColor]としても表示するにはどうすればよいですか?