0
當我調用DidSelectRowAtIndexPath時,我正在檢查單元格是否已被檢查,如果是,請檢查覈心數據中的鍵。 (這個過程允許我將導航按鈕從零設置爲添加,如果項目被選中)。我也想把選定的項目放在一個數組(或集合)中,這樣我可以在我的Add方法中調用它(以保存到Core Data)。我已經在頭文件中聲明瞭checkedArray,但它只會將最後選中的單元格保存到數組中。什麼是正確的方法來做到這一點?如何將迭代對象添加到NSMutableArray中
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];