The stuff outside of the if (cell == nil) block will be performed on each cell, 
whether new or reused.  You need to assume that the current display of the cell 
is "wrong", and do what is necessary to make it right.

In this case, if one of your red cells gets reused for rows 0-3, there is 
nothing here defining what the color should be.  So it will remain red.  Add an 
else condition that defines what the color should be for rows 0-3.

Brian


On Nov 23, 2009, at 8:02 PM, Philip Vallone wrote:

> Hi List,
> 
> If I have an UITableViewCell and want to set the cell attributes based on 
> indexPath.row number, how could I do this? In the below example, the cells 
> are drawn dynamically and work until the user moves the table. When the first 
> 4 four rows are redrawn, their font changes. How do I set the first four rows 
> to a color and not have it change? 
> 
> 
> - (UITableViewCell *)tableView:(UITableView *)tableView 
> cellForRowAtIndexPath:(NSIndexPath *)indexPath {
> 
> 
>       NSLog(@"Painting Row Number %d",        indexPath.row);
>       
>       static NSString *CellIdentifier = @"Cell";    
>       UITableViewCell *cell = [tableView 
> dequeueReusableCellWithIdentifier:CellIdentifier];
>       if (cell == nil) {
> 
>               cell = [[[UITableViewCell alloc] 
> initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] 
> autorelease];
> 
>       }
>       
>       [cell.textLabel setText:[tableList objectAtIndex:indexPath.row]];       
>       [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
>       
>       cell.textLabel.font = [UIFont systemFontOfSize:14];
>       cell.textLabel.numberOfLines = 2;
>       
>       if (indexPath.row > 3) {
>                                       
>               cell.textLabel.textColor = [UIColor redColor];          
>               
>       }
>       
> 
> return cell;
> }
> 
> Thanks,
> 
> Phil_______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/brianslick%40mac.com
> 
> This email sent to briansl...@mac.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to