私は、テストの結果を表示するテーブルビューを持つ簡単なアプリケーションを作っています。結果は単純な配列から来ています。配列には数字だけがあり、テストのスコアは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];
を入力すると、すべて緑色になります。
ありがとうございました。 –