当我调用 DidSelectRowAtIndexPath 时,我正在检查是否检查了单元格,如果是,请检查核心数据中的键。(此过程允许我将导航按钮从 nil 设置为 Add 如果选中项目)。我还想将所选项目放入一个数组(或集合)中,以便我可以在我的 Add 方法中调用它(以保存到核心数据)。我已经在头文件中声明了checkedArray,但它只将最后选择的单元格保存到数组中。这样做的正确方法是什么?
Athlete *checkedAthlete = (Athlete *)[self.fetchedResultsController objectAtIndexPath:indexPath];
[checkedAthlete setValue:[NSNumber numberWithBool:targetCustomCell.checked] forKey:@"athleteChecked"];
BOOL hasChecked = NO;
for (checkedAthlete in self.fetchedResultsController.fetchedObjects)
{
BOOL isChecked = [[checkedAthlete valueForKey:@"athleteChecked"] boolValue];
if (isChecked)
{
hasChecked = YES;
checkedArray = [[NSMutableArray alloc] initWithObjects:checkedAthlete,nil];
//NSLog(@"%@",checkedArray);
}
}
我还在标题中声明了 NSMutableSet 并尝试了:
[testSet = [NSMutableSet set] addObject:checkedAthlete];