【发布时间】:2012-12-11 18:37:53
【问题描述】:
大家好,我对 ios 还很陌生,所以还有很多东西要学习,我将一个具有动态背景颜色的子视图从 web 服务添加到表格单元格,但是在选择子视图时,背景颜色正在更改为表格单元格的选定状态颜色,我知道为什么要这样做,因为它会更改视图中的所有子视图背景颜色,我似乎无法弄清楚如何阻止它更改子视图背景颜色,我希望它保持选择的动态颜色?
array = [colors objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *colorBox = [[UIView alloc] initWithFrame:CGRectMake(10,10,20,20)];
[colorBox setTag:1];
[cell.contentView addSubview:colorBox];
}
UIView *box = [cell viewWithTag:1];
box.backgroundColor = [self colorForBox:array.color];
return cell;
然后获取颜色
- (UIColor *)colorForTransport:(NSString*)Line {
if([Line isEqualToString:@"Brown"])
return [UIColor colorWithRed:0.682 green:0.38 blue:0.094 alpha:1];
else if([Line isEqualToString:@"Red"])
return [UIColor colorWithRed:0.894 green:0.122 blue:0.122 alpha:1];
else
return DefaultBackgroundColor;
}
任何帮助将不胜感激谢谢!
【问题讨论】:
-
我不明白这个问题。你想阻止什么?
标签: objective-c uitableview addsubview