【问题标题】:TableViewCell Appearance only changes the cell's currently in the viewUITableViewCell 外观只改变当前视图中的单元格
【发布时间】:2014-03-18 03:55:46
【问题描述】:

使用 UIAppearance,我正在更改表格视图单元格的标签颜色。这工作正常,但它只为当前看到的单元格着色。所有单元格的视图(不可见)仍然是默认颜色(黑色)。

总而言之,该方法仅更改当前可见的单元格,而不是超出视图(滚动视图)的单元格。

这是我的 UIAppearance 代码:

[[UILabel appearanceWhenContainedIn:[_textLabel class], nil]
 setTextColor:[UIColor colorWithRed:(204.0f/255.0f) green:(204.0f/255.0f) blue:(204.0f/255.0f) alpha:1.0f]];

【问题讨论】:

  • 你能发布更多代码吗?比如你调用这些方法的部分。

标签: ios uilabel uiappearance


【解决方案1】:

我猜你这里有一个错字,_textLabel 必须是 UITableViewCell 而不是 UILabel

[[UILabel appearanceWhenContainedIn:[YourTableViewCell class], nil]
 setTextColor:[UIColor colorWithRed:(204.0f/255.0f) green:(204.0f/255.0f) blue:(204.0f/255.0f) alpha:1.0f]];

您可以在cellForRowAtIndexPath 中检查重用单元格:

static NSString *CellIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

【讨论】:

  • 不,这是一个 UILabel,因为问题在于单元格的标题,而不是单元格的背景颜色。
  • 不管怎样,_textLabel 是 UITableViewCell 的一部分
  • 这和我做的一样,只是直接调用 UITableViewCell
  • 这不是问题。问题是我调用的代码只会改变当前可视区域中单元格的文本颜色。
  • 嗯,你能把你的cellForRowAtIndexPath发一下吗。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-29
  • 2020-02-24
  • 2019-02-06
  • 1970-01-01
  • 2021-04-25
  • 1970-01-01
相关资源
最近更新 更多