1
我想更改所選單元格背景顏色並在該單元格上保留文本。然後,我確實喜歡這樣,它可以改變單元格的顏色,但單元格上的文字將會消失。如何更改所選單元格背景顏色而不丟失文本
- (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;
}
是什麼顏色的文字? – Chris 2014-10-11 18:58:37
[更改選定單元格的背景顏色?]的可能重複(http://stackoverflow.com/questions/2418189/iphone-uitableviewcell-changing-background-color-of-selected-cell) – jww 2014-10-11 19:42:20
您不應該出列新的細胞。獲取對使用表視圖方法cellForRowAtIndexPath:選擇的單元格的引用。 – rdelmar 2014-10-11 19:50:59