我有一个表格视图。在此我想设置的第一个单元格alone..Others的颜色应该是白色的...我怎样才能做到这一点如何在iPhone上的表格视图中设置单个单元格的背景颜色
我需要你的帮助....
在此先感谢... ..
我有一个表格视图。在此我想设置的第一个单元格alone..Others的颜色应该是白色的...我怎样才能做到这一点如何在iPhone上的表格视图中设置单个单元格的背景颜色
我需要你的帮助....
在此先感谢... ..
在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;
}
你应该做的颜色变化,在“willDisplayCell”委托方法,而不是在其“的cellForRowAtIndexPath”的创作。 否则,当向电池添加附件时,它可能不会粘住或显示不良。
看看这个帖子了解更多详情:Setting background color of a table view cell on iPhone
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];
}