我正在制作一个带有显示测试结果的tableview的简单应用程序。结果来自一个简单的数组。在阵列中只有数字,测试分数介于0和100之间。基于单元格内容的UITableView单元格颜色
我试图让UITableView行根据结果更改颜色。大于或等于75将显示绿色背景,> = 50 & & < 75将是黄色,> 50将是红色。
这是我到目前为止。我的理解很基础。
- (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];
}
// Configure the cell...
// Set up the cell...
NSUInteger row = [indexPath row];
cell.textLabel.text = [scoresArray objectAtIndex:row];
// THIS IS WHERE I NEED HELP TO GET THE VALUE FROM THE ARRAY
// INTO ????
if (???? >=75) {
cell.contentView.backgroundColor = [UIColor greenColor];
}
if (???? >=50 && ???? <75) {
cell.contentView.backgroundColor = [UIColor yellowColor];
}
if (???? >=0 && ???? <50) {
cell.contentView.backgroundColor = [UIColor redColor];
}
else {
cell.contentView.backgroundColor = [UIColor whiteColor];
}
return cell;
}
#pragma mark UITableViewDelegate
- (void)tableView: (UITableView*)tableView willDisplayCell:
(UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
cell.backgroundColor = cell.contentView.backgroundColor;
}
如果我只是把cell.contentView.backgroundColor = [UIColor greenColor];
,例如,他们都去绿色。
谢谢你的帮助。 – 2012-03-17 06:11:18