我正在尝试在UITableViewiPhone 中实现此功能:始终只有 FIRST 和 LAST VISIBLE 单元格具有不同的背景颜色,例如红色,而其他单元格的颜色保持白色。滚动过程中的平滑变化。
我试过了:
在.m文件中:
NSIndexPath *firstRow;
UITableViewCell* firstCell;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"tableCell";    
    tableCell *cell = (tableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) 
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"tableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    } 
    cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
    //cell.thumbnailImageView.image = image;
    return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
{
    NSArray *visible = [tableView indexPathsForVisibleRows];
    firstRow = (NSIndexPath *)[visible objectAtIndex:0];
    firstCell = [tableView cellForRowAtIndexPath:firstRow];
    firstCell.contentView.backgroundColor=[UIColor redColor];
    NSLog(@"main visible cell's row: %i", firstRow.row);
    [tableView endUpdates];
    firstCell.contentView.backgroundColor=[UIColor redColor];   
}
但是向上滚动时颜色不会更新。