1

我有一个 TableView,我想在点击它时为一行添加一个复选标记。为此,我有:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        NSString *selectedCountry = [self.files objectAtIndex:indexPath.row];
        NSString *Documents = [[NSBundle mainBundle] pathForResource:selectedCountry ofType:@"ppt" inDirectory:@"thepowerpoints"];
        //NSLog(@"%@", selectedCountry);
        UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];

        if (newCell.accessoryType == UITableViewCellAccessoryNone) {
            if (self.chosen == nil) {
                self.chosen = [[NSMutableArray alloc] init];
            }
            newCell.accessoryType = UITableViewCellAccessoryCheckmark;
            [self.chosen addObject:Documents];
             NSLog(@"%@", self.chosen);

        }else {
            newCell.accessoryType = UITableViewCellAccessoryNone;
            [self.chosen removeObject:Documents];
        }

        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];


}

我知道这是由于dequeueReusableCellWithIdentifierCell 的类型而发生的。我的问题是,我可以改变什么,以便只有被点击的行得到复选标记,而不是所有这些其他单元格,一旦它们开始被重用?

4

1 回答 1

2

将决定是否应检入单元格的代码移至 cellForRowAtIndexPath。保留对当前选定索引/项目的引用,然后在该单元格上设置复选标记。您可以将未选中的单元格设置为将附件视图设置为无。

于 2015-12-10T17:43:38.060 回答