UITableViewCell textLabel颜色不变 [英] UITableViewCell textLabel color not changing
本文介绍了UITableViewCell textLabel颜色不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UITableView和cellForRowAtIndexPath方法我正在更改单元格的一些属性(字体,大小等)现在,除了更改textLabel的颜色外,下面列出的所有赋值都可以正常工作。我无法弄清楚为什么只有那个特定的颜色属性不会改变。我看到了我能想到的任何地方,弄清楚为什么它不起作用而且我被卡住了。有任何想法吗?
I've got a UITableView and as the cellForRowAtIndexPath method I am changing some attributes of the cell (font, size, etc.) Now all of the assignments listed below work just fine except changing the color of the textLabel. I can't figure out why only that specific color attribute won't change. I've looked about everywhere I can think of to figure out why it isn't working and I'm stuck. Any ideas?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kLocationAttributeCellID = @"bAttributeCellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kLocationAttributeCellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kLocationAttributeCellID] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica" size:14.0];
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.userInteractionEnabled = NO;
cell.textLabel.font = [UIFont fontWithName:@"Courier" size:18.0];
cell.textLabel.textColor = [UIColor redColor]; // this never takes effect...
}
cell.textLabel.text = @"Test Label";
cell.detailTextLabel.text = @"Test Details";
return cell;
}
推荐答案
这是因为:
cell.userInteractionEnabled = NO;
如果您不想选择细胞,请尝试使用此选项:
If you don't want your cells to be selectable, try using this instead:
cell.selectionStyle = UITableViewCellSelectionStyleNone;
这篇关于UITableViewCell textLabel颜色不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文