【发布时间】:2012-06-26 18:35:47
【问题描述】:
我有一个大型自定义UITableView,每行都有UILabels,我想以黑色或绿色显示某些文本。
我用来自NSArray 的NSString's 喂细胞。假设我只想将索引30 中的NSString 显示为黑色。
我正在尝试这样的事情,但它不起作用:
NSIndexPath *indexPathWithBlackText = [NSIndexPath indexPathForRow:30 inSection:[indexPath section]];
if (indexPath.row == indexPathWithBlackText.row) {
//Label with text in black
topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
} else {
//Label with text in green
topLabel.textColor = [UIColor colorWithRed:0.122 green:0.467 blue:0.255 alpha:1.00];
}
任何关于正确方向的提示将不胜感激。谢谢!
【问题讨论】:
-
为什么不这样做 if (indexPath == indexPathWithBlackText) ?您在代码中的哪个位置执行此操作?
-
我只是想将黑色或绿色的文本标签分配到一个固定的位置,与提供单元格的 NSArray 中的索引相同。问题是,当我滚动 UITableView 时,其他文本也会改变颜色,而不仅仅是我想要的行中的颜色,我认为这是由于 UITableView 动态绘图。
标签: objective-c cocoa-touch uitableview uilabel