【发布时间】:2014-12-06 17:25:54
【问题描述】:
我想更改所选单元格的背景颜色并将文本保留在该单元格上。然后我就这样做了,它可以改变单元格颜色但单元格上的文本会消失。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"MessageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.receivedData objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"MessageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIView *bgColorView = [[UIView alloc]init];
bgColorView.backgroundColor = [UIColor colorWithRed:0.529 green:0.808 blue:0.922 alpha:0.5];
cell.selectedBackgroundView = bgColorView;
}
【问题讨论】:
-
文字是什么颜色的?
-
您不应该将新单元格出列。使用表格视图方法获取对您选择的单元格的引用,cellForRowAtIndexPath:.
标签: ios uitableview colors background