【问题标题】:background color of UILabel is become clear after reload TableUILabel 的背景颜色在重新加载表后变得清晰
【发布时间】:2017-03-30 06:45:48
【问题描述】:

我在 UiTableViewController 中工作,并使用 XIB 创建了自定义单元格。我只是将黑色设置为一个标签。听说我附上了三张图片以便更好地解释。

didSelectRowAtIndexPath 方法中选择时,我将其从黑色更改为蓝色。

主要问题是当我滚动表格时,该标签的背景颜色变得清晰。

在 cellForRowAtIndexpath 方法中,我只是添加了这个条件,

if (inboxSelcted == 1) { 
  cell.lblNoOfIndexItem.backgroundColor = [UIColor blueColor]; 
} else { 
  cell.lblNoOfIndexItem.backgroundColor = [UIColor blackColor]; 
} 

【问题讨论】:

  • 能否为 cellForRowAtIndexpath 添加代码?
  • 你能用cellForRow atindexPath函数编辑吗?
  • 在 cellForRowAtIndexpath 方法中,我只是添加了这个条件, if (inboxSelcted == 1) { cell.lblNoOfIndexItem.backgroundColor = [UIColor blueColor]; } else { cell.lblNoOfIndexItem.backgroundColor = [UIColor blackColor]; }
  • @PALAKiOSDeveloper 更新您问题中的代码
  • 你能检查一下这个条件检查的外部范围吗?您可能有一些来自出队单元的默认行为(基本上来自 IB-UI)。如果是这种情况,您可以在单元格初始行之后为标签设置任何一种颜色。

标签: ios css objective-c uitableview uilabel


【解决方案1】:

cellForRowAtIndexpath 方法中,根据您的屏幕截图收件箱索引为 2 尝试这样的操作。所以,

if (indexPath.row == 2) { 
 cell.lblNoOfIndexItem.backgroundColor = [UIColor blueColor]; 
} else { 
 cell.lblNoOfIndexItem.backgroundColor = [UIColor blackColor]; 
} 

而在didSelectRowAtIndexPath方法中,

if (indexPath.row == 2) { 
 inboxSelcted = indexPath.row; 
}

试试这样,告诉我,它行得通!

【讨论】:

  • 谢谢安东尼拉斐尔。只有我想补充一下,我只是将您的答案“3”更改为“2”及其工作原理。再次感谢先生。
猜你喜欢
  • 1970-01-01
  • 2021-10-26
  • 1970-01-01
  • 2017-02-11
  • 1970-01-01
  • 2012-06-16
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
相关资源
最近更新 更多