设置单元格选定的背景视图删除backgroundview

时间:2012-10-07 08:46:29

标签: objective-c ios user-interface uitableview

我正在尝试设置自定义UITableViewCells。我可以设置backgroundView没问题,但是如果我设置selectedBackgroundView,则单元格的背景变为白色,只显示所选背景:

- (void) createCell: (UITableViewCell*)cell onRow: (NSUInteger)row
{
UIImageView* bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell_background_red.png"]];
cell.backgroundView = bgImage;
cell.selectedBackgroundView = bgImage;
cell.textLabel.hidden = YES;

UILabel* titleLabel = [[UILabel alloc] initWithFrame: CGRectMake(20, CGRectGetHeight(cell.frame) / 2, 200, 50)];
titleLabel.text = [[self.ruleList objectAtIndex: row] objectForKey: TitleKey];
titleLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview: titleLabel];

}

1 个答案:

答案 0 :(得分:3)

您正在为backgroundView和selectedBackgroundView设置相同的图像。

cell.backgroundView = bgImage;
cell.selectedBackgroundView = bgImage;

当你这样做时,两者都重叠并产生白色背景,或者你只能看到背景选择的视图。