我有一个 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];
}
我知道这是由于dequeueReusableCellWithIdentifier
Cell 的类型而发生的。我的问题是,我可以改变什么,以便只有被点击的行得到复选标记,而不是所有这些其他单元格,一旦它们开始被重用?