gpt4 book ai didi

ios - 为 UITableViewCell 中的特定单元格设置颜色

转载 作者:行者123 更新时间:2023-11-29 00:19:13 26 4
gpt4 key购买 nike

我正在尝试将 UITableViewCell 中特定单元格的背景颜色设置为紫色。

到目前为止,我已经尝试过此操作,它将所有单元格的颜色设置为紫色,而不仅仅是第一个单元格。

cellForRowAtIndexPath 方法中:

for(int k = 0; k < queueMCDate.count; k++){
if(_qbColorArr.count == 0) {

}
else if ([[_qbColorArr objectAtIndex:k] isEqual:@"a"]) {
if(indexPath.row == k)
cell.backgroundColor = [UIColor colorWithRed:0.48 green:0.04 blue:0.41 alpha:1.0];
}
}

return cell;
}

这是一个显示其当前外观的链接。

Link

我希望应用程序的工作方式是,在第一个单元格中设置返回日期后,我希望它是紫色的。经过, 为它们分配一个字符串值a,当我设置返回日期时,我希望它能起作用。


编辑:

cellForRowAtIndexPath方法中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
QueueDetails *cell = [tableView dequeueReusableCellWithIdentifier:@"reuCell" forIndexPath:indexPath];

cell.queueNo.text = fQueueNo[indexPath.row];
cell.queueeName.text = queueNameDisp[indexPath.row];
cell.bkTitle.text = queueBk[indexPath.row];
cell.dateRe.text = queueRDate[indexPath.row];
cell.dateBo.text = queueBDate[indexPath.row];

for(int k = 0; k < queueRDate.count; k++){
if(_qbColorArr.count == 0) {
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
else if ([[_qbColorArr objectAtIndex:k] isEqual:@"a"]) {
if(indexPath.row == k)
cell.backgroundColor = [UIColor colorWithRed:0.48 green:0.04 blue:0.41 alpha:1.0];
return cell;
else{
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
}
}


}

单元格在开始时默认为白色,但是当将归还日期添加到单元格时,该单元格需要变为紫色,表示已归还一本书,而其他人则保持白色。

为了更好地澄清,我使用 _qbColorArr 的原因是因为该数组包含空白(在 viewDidLoad 初始化)或 a。因此,当我设置第一个单元格的返回日期时,我也执行了此操作 [_qbColorArr ReplaceObjectAtIndex:0 withObject:@"a"]。然后将在 else if 语句中检查这一点,并将单元格的颜色指定为紫色。

最佳答案

您没有在 else 条件下设置默认颜色。一旦行的颜色设置为紫色,那么由于重用标识符,颜色保持不变。设置默认颜色如下:-

for(int k = 0; k < queueMCDate.count; k++){
if(_qbColorArr.count == 0) {
cell.backgroundColor = [UIColor whiteColor];//Your Default Color will go here
}
else if ([[_qbColorArr objectAtIndex:k] isEqual:@"a"]) {
if(indexPath.row == k)
cell.backgroundColor = [UIColor colorWithRed:0.48 green:0.04 blue:0.41 alpha:1.0];
else{
cell.backgroundColor = [UIColor whiteColor];//Your Default Color will go here
}
}
}

return cell;

关于ios - 为 UITableViewCell 中的特定单元格设置颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453925/

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