これが繰り返される質問であることは知っていますが、この問題の解決策が得られません。
ステータスフォームのWebサービスに従って、1つのテキストラベルの色を変更したいテーブルビューを使用しています。
しかし、問題は、テーブル ビューを上下にスクロールすると、すべてのテキスト ラベルの色が変化することです。これが私のコードです。
- (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...
cell.textLabel.text = [[self.Contents objectAtIndex:indexPath.row]event];
if([[[self.Contents objectAtIndex:indexPath.row]status] isEqualToString:@"Failed"]){
cell.textLabel.textColor = [UIColor redColor];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}
条件がコメントされている場合、cell ==nil
正常に機能していますが、これが正確な方法ではないことはわかっています。
誰でもこれで私を助けてくれませんか。前もって感謝します。