无法更改UITableViewCell的文本颜色

时间:2012-03-15 18:23:27

标签: ios uitableview

我有一个包含默认样式单元格的UITableView。在Xcode 41B中,我无法更改单元格内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; 
}

2 个答案:

答案 0 :(得分:2)

我正在添加这个,因为在我寻找ans之前的几个时刻,我没有在这里找到.. 所以对于未来的旅行者..,

使用此方法

 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
 {

      //Your-code-goes-here---sample->
        tCell.cellLabel.textColor = [UIColor grayColor];

  }

希望这会有所帮助。

答案 1 :(得分:1)

确保reuseIdentifier与IB中的匹配。对我来说很好。

相关问题