2010-01-27 30 views
1

我已經閱讀了關於分離UITableView的單元格的帖子,但一直未能解決細節問題。我的代碼是:Stripe UITableView的行

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    // Setup code omitted 

    cell.textLabel.text = @"Blah Blah"; 
    cell.detailTextLabel.text = @"Blah blah blah"; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    if ([indexPath row] % 2 == 1) { 
     cell.contentView.backgroundColor  = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
     cell.textLabel.backgroundColor  = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.0]; 
     cell.detailTextLabel.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
     cell.accessoryView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]; 
    } 
    return cell; 
} 

我的結果是:

http://img2.pict.com/18/df/b9/2661271/0/screenshot20100127at3.png

任何想法,爲什麼發生這種情況?謝謝!

回答

4

這些細胞得到重用,你應該將其設置回正常的[indexpath row] % 2 == 0

+0

難道是這樣,但它並沒有解決任何事情。上面看到的效果仍然相同。 – 2010-01-27 21:54:33

2
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
     [cell setBackgroundColor: indexPath.row % 2 == 0 ? color1 : color2]; 

}