我已經作爲走得更遠,使用以下代碼來設置TableView中單元格的背景顏色(在的cellForRowAtIndexPath)細胞背景顏色僅示出了對文本
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor = [UIColor yellowColor];
cell.contentView.backgroundColor = [UIColor yellowColor];
UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ];
backgroundView.backgroundColor = [ UIColor yellowColor ];
cell.backgroundView = backgroundView;
for (UIView* view in cell.contentView.subviews)
{
view.backgroundColor = [ UIColor yellowColor ];
}
}
// Set up the cell...
if ([[menuList objectAtIndex:indexPath.row] isKindOfClass:[Category class]])
{
cell.text = ((Category *)[menuList objectAtIndex:indexPath.row]).name;
}
else
{
[cell setText: [menuList objectAtIndex:indexPath.row]];
}
return cell;
}
然而,當它呈現僅一部分單元格的背景應用類似於此(其中z是bg填充),即使輔助設備的背景是彩色的,但不是文本。
xxxxxxxxxxxxxxxxxxxx
zzzSearch
xxxxxxxxxxxxxxxxxxxx
我看到能夠改變文本的背景的唯一方法是通過設置整個表格視圖的背景色在Interface Builder
感謝聽起來像一個有前途的根到解決方案。我已經嘗試了你的建議(請參閱上面的更新代碼示例),但仍然沒有快樂,有什麼建議? – 2009-02-10 10:52:59