在iOS开发中实现UITableView时,一般是在delegate方法[UITableViewDataSource tableView:cellForRowAtIndexPath:]对table中的每个cell进行初始化等操作。按照一般的逻辑,对cell的backgroundColor也同样需要在此进行,实现的代码往往是这样:
<span style="font-size:14px;">- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"menuCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
...
cell.backgroundColor = [UIColor whiteColor];
...
return cell;
}</span>
但经过简单的测试就能发现,在iOS 7及以上的系统中没问题,backgroundColor设置正常,但是在iOS 6及以下的系统中