0

MELCore Dataのリストを使用しUITableViewControllersて表示するアプリを作成しています。

私はすべてをやりましたが、UITableViewCell編集可能かどうかをチェックすることはできません。これは、私の問題を想像するのに役立つはずのアプリのスクリーンショットです。

ここに画像の説明を入力

セクションがあるかどうかを確認しchapterています。これが true の場合はすべてが黒で表示され、そうでない場合はdetailTextLabel色が赤に変更されます。しかし、ご覧のとおり、一部のセルにはセクションがあっても色が付けられています。それはどのように可能ですか?

これが私のtableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Initializing Cell and filling it with info
    Chapter *chapter = [self.MELs objectAtIndex:indexPath.row];

    cell.detailTextLabel.text = [NSString stringWithFormat:@"Number: %@ \t Sections: %lu", chapter.number, (unsigned long)[chapter.sections count]];
    cell.textLabel.text = [chapter.title capitalizedString];

    if ([chapter.sections count] == 0) {
        [cell.detailTextLabel setTextColor:[UIColor redColor]];
    }

    return cell;
}
4

3 に答える 3

3

セルが再利用されるため、条件が満たされない場合は textcolor をデフォルトにリセットする必要があります。

if ([chapter.sections count] == 0) {
    [cell.detailTextLabel setTextColor:[UIColor redColor]];
} else {
    [cell.detailTextLabel setTextColor:[UIColor blackColor]];
}
于 2013-10-14T09:42:20.113 に答える