How to set only the first cell of a UITableView to a different color?

Posted by Ted on Stack Overflow See other posts from Stack Overflow or by Ted
Published on 2012-11-22T16:48:19Z Indexed on 2012/11/22 16:59 UTC
Read the original article Hit count: 168

Filed under:
|

I use cellForRowAtIndexPath like here:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil)
        cell = [self getCellContentView:CellIdentifier];


    UILabel *lbl = (UILabel*)[cell.contentView viewWithTag:1];

    for (UITableViewCell *c in [tbl visibleCells])
    {
     //   UITableViewCell *cell2 = [tbl cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        UILabel *lbl = (UILabel*)[c.contentView viewWithTag:1];
        lbl.textColor = [UIColor redColor];
    }

    if([tbl indexPathForCell:cell].section==0)
        lbl.textColor = [UIColor whiteColor];


    UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
    UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];

    //First get the dictionary object

    lblTemp1.text =  @"test!";
    lblTemp2.text = @"testing more";

    NSLog(@"%@",[tbl indexPathForCell:cell]);

    return cell;


}

But is still makes some of my cells white instead of gray.

How can I change only the first item in the row to white?

© Stack Overflow or respective owner

Related posts about ios

Related posts about xcode