2010-08-26 91 views

回答

2

在cellForRowAtIndexPath中,检查indexPath.row == 0,然后设置自定义背景。否则,设置默认背景。

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    if (indexPath.row == 0) { 
     //set custom background color 
    } else { 
     //set default background color 
    } 
    return cell; 
} 
0

你应该做的颜色变化,在“willDisplayCell”委托方法,而不是在其“的cellForRowAtIndexPath”的创作。 否则,当向电池添加附件时,它可能不会粘住或显示不良。

看看这个帖子了解更多详情:Setting background color of a table view cell on iPhone

0
if(indexPath.row == 0) 
     { 
      UIView *bg = [[UIView alloc] initWithFrame:cell.frame]; 
      bg.backgroundColor = [UIColor colorWithRed:175.0/255.0 green:220.0/255.0 blue:186.0/255.0 alpha:1]; 
      cell.backgroundView = bg; 
      [bg release]; 
     } 
相关问题