Я делаю простое приложение с табличным представлением, которое отображает результаты теста. Результаты приходят из простого массива. В массиве есть только цифры, результаты тестов от 0 до 100.
Я пытаюсь получить строку 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];
, они все станут зелеными.