Bassman
Bassman

Reputation: 413

Cannot change text color of UITableViewCell

I have a UITableView containing Default style cells. In Xcode 4 IB, I cannot change the color of the textLabel within the cell. I can, however change the Font face & size, # of lines per cell, etc. Just not the text color. Interestingly, I cannot do it programmatically either.

// 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; 
}

Upvotes: 1

Views: 2285

Answers (2)

mavericks
mavericks

Reputation: 1589

I'm adding this because couple of moments before i was looking for the ans, And I didn't find here.. so for future voyager..,

Use this method

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

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

  }

Hope this would help.

Upvotes: 4

LJ Wilson
LJ Wilson

Reputation: 14427

Make sure that the reuseIdentifier matches what is in IB. Works fine for me.

Upvotes: 1

Related Questions