gpt4 book ai didi

iphone - 如何根据位置修改空 UITableViewCell 对象的背景颜色?

转载 作者:可可西里 更新时间:2023-11-01 04:44:51 25 4
gpt4 key购买 nike

我正在尝试编写代码以根据单元格在表格中的位置修改单元格的背景颜色。虽然以下代码“有效”,但它只会影响传递给它的单元格。空单元格不会受到影响。

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
if(!indexPath.row%2)
{
cell.backgroundColor = [UIColor colorWithRed: 0.0 green: 0.0 blue: 1.0 alpha: 1.0] ;
NSLog(@"Blue");
}
else{
cell.backgroundColor = [UIColor whiteColor];
NSLog(@"white");
}
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}

当列表中的项目很少时,如何影响显示的其余单元格(如果为空)?

“空”单元格是指当您的数据源没有足够的数据来填充提供给 TableView 的整个 View 时显示的占位符单元格。例如,如果您可以容纳 10 个单元格,但只有 5 个数据值,那么您只能处理 5 个单元格 - 接下来的 5 个单元格是空的,据我所知,无法访问。

最佳答案

我想您只想更改“空”单元格的背景……然后您可以在 UITableView 的 InterfaceBuilder 中更改背景颜色。但它会影响所有空单元格。

您还可以更改分隔符类型。

此外,请看这里:http://www.zenbrains.com/blog/en/2010/06/color-de-fondo-de-celdas-vacias/

编辑:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// 7 depends on how many cell is shown
return ([source count] <= 7) ? 7 : [source count];
}

发件人:Show blank UITableViewCells in custom UITableView

关于iphone - 如何根据位置修改空 UITableViewCell 对象的背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3888346/

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