2010-08-26 36 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]; 
     } 
相關問題