【问题标题】:Cannot change text color of UITableViewCell无法更改 UITableViewCell 的文本颜色
【发布时间】:2012-03-15 18:23:26
【问题描述】:

我有一个包含默认样式单元格的 UITableView。在 Xcode 4 IB 中,我无法更改单元格内 textLabel 的颜色。但是,我可以更改字体和大小、每个单元格的行数等。只是不能更改文本颜色。有趣的是,我也不能以编程方式做到这一点。

// Give the table view a cell to display for a single row
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // reuse or create the cell
    static NSString *cellID = @"MyCustomCellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];   
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }

    // NOTE: the setting below does not work when set either here or in IB.
    cell.textLabel.textColor = [UIColor yellowColor];   

    // set the text for the cell
    cell.textLabel.text = [appDelegate.sharedData.arrayFaves objectAtIndex:indexPath.row];

   return cell; 
}

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    我添加这个是因为在我寻找答案之前的几分钟,我没有在这里找到.. 所以对于未来的航海者..,

    使用这个方法

     -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
     {
    
          //Your-code-goes-here---sample->
            tCell.cellLabel.textColor = [UIColor grayColor];
    
      }
    

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      确保reuseIdentifier 与IB 中的内容相匹配。适合我。

      【讨论】:

      • 我检查过 - 它们是相同的。感谢您的建议。
      • 如果您将项目压缩并粘贴到您的公共 Dropbox 文件夹中,我会看一看。
      • 完成。我应该给你发个链接吗?
      • 嗯,我找不到在这个网站上私信的方法。我怎样才能私下联系你?
      • www.irockios.com 对帖子发表评论。我会给你回邮件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 2011-02-01
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      相关资源
      最近更新 更多