Ios UITableView';正在多个单元格上重用的s AccessoryView
我有一个TableView,我想在点击一行时为它添加一个复选标记。为此,我:Ios UITableView';正在多个单元格上重用的s AccessoryView,ios,objective-c,uitableview,accessoryview,Ios,Objective C,Uitableview,Accessoryview,我有一个TableView,我想在点击一行时为它添加一个复选标记。为此,我: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *selectedCountry = [self.files objectAtIndex:indexPath.row]; NSString *Documents = [[NSBund
- (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
导致的。我的问题是,我可以更改什么,以便在重新使用这些单元格时,只有被点击的行才能获得选中标记,而不是所有其他单元格?移动决定是否将单元格签入cellForRowAtIndexPath的代码。保留对当前选定索引/项的引用,然后在该单元格上设置复选标记。您可以将未选择的单元格设置为“附件视图”为“无” 好的,那么你是说在didSelect中,为该单元格设置一个布尔值,在cellForRowAtIndexPath中有一个if/else语句为某个特定的单元格查找该布尔值?不要在单元格上放置标志,记住它正在被重用。在视图控制器上放置一个选定的索引属性,并在didSelect中进行设置。是否尝试将“行在索引”方法的“单元格”中的其他单元格的accessoryview设置为“无”