gpt4 book ai didi

ios - 更改 UITableView 的单元格颜色

转载 作者:行者123 更新时间:2023-11-29 04:34:38 25 4
gpt4 key购买 nike

我试图更改填充 UITableView cell.backgroundColor=[UIColor blueColor]; 的单元格的颜色但单元格仍然保持黑色。

 -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

if (tofriend) {

if (indexPath.section==0){


static NSString *CellIdentifier;
CellIdentifier= @"MyCell";


MyCell *cell =(MytCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if (!cell) {
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil]; cell = myCell;


}
cell.backgroundColor=[UIColor blueColor];

好的,我明白了它是 cell.contentView.backgroundColor。

最佳答案

由于单元格缓存,您应该在委托(delegate)方法中更改背景颜色:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
}

cell.backgroundColor将在此方法中正确显示。

关于ios - 更改 UITableView 的单元格颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11232886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com