微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – UITableViewCell textLabel颜色不变

我有一个UITableView和cellForRowAtIndexPath方法我正在更改单元格的一些属性(字体,大小等)现在除了更改textLabel的颜色外,下面列出的所有赋值都可以正常工作.我无法弄清楚为什么只有那个特定的颜色属性不会改变.我看到了我能想到的任何地方,弄清楚为什么它不起作用而且我被卡住了.有任何想法吗?
- (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;

如果您不希望您的单元格可选,请尝试使用此代码

cell.selectionStyle = UITableViewCellSelectionStyleNone;

原文地址:https://www.jb51.cc/iOS/334500.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐