1

これを機能させるためにあらゆることを試しましたが、スクロールcellForRowAtIndexPathすると、テーブルビューにチェックマークが追加および削除されているようです。誰か助けてもらえますか?

// Configure the cell...
cell.textLabel.text = [currencyList objectAtIndex:indexPath.row];

// Check to see what currency is currently selected and checkstyle
if ([selectedCurrency isEqualToString:cell.textLabel.text]) {

    // Add a tick to the selected row
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    // Change the text colour
    cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0.5 alpha:1];
    self.checkedIndexPath = indexPath;
} else {
    UITableViewCell *uncheckCell = [self.tableView
                                    cellForRowAtIndexPath:self.checkedIndexPath];
    uncheckCell.accessoryType = UITableViewCellAccessoryNone;
    // Change the font colour back to black
    uncheckCell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
4

1 に答える 1

1

You don't need to uncheck cell in cellForRowAtIndexPath. Better sollution is just reload checked cell.

- (void)setCheckedIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath *uncheckIndexPath = self.checkedIndexPath;
    _checkedIndexPath = indexPath;
    [self.tableView reloadRowsAtIndexPaths:@[uncheckIndexPath]
                          withRowAnimation:UITableViewRowAnimationLeft];
}

And change cellForRowAtIndexPath. Please note that we set UITableViewCellAccessoryNone to cell that we must return, not for cell that you want to uncheck.

// Configure the cell...
cell.textLabel.text = [currencyList objectAtIndex:indexPath.row];

// Check to see what currency is currently selected and checkstyle
if ([selectedCurrency isEqualToString:cell.textLabel.text]) {

    // Add a tick to the selected row
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    // Change the text colour
    cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0.5 alpha:1];
    self.checkedIndexPath = indexPath;
} else {
    //If cell unchecked
    cell.accessoryType = UITableViewCellAccessoryNone;
    // Change the font colour back to black
    cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
于 2013-03-11T22:01:05.990 に答える