0
我需要更新核心數據中所需單元格的值。我有一個對我有價值的單元(ID)。我需要找到價值並取代。我知道如何改變數組的元素。以下顯示了我是如何做到的。但是我必須在MyBase中更改字段(ID)。我需要更改的值將等於fromIndexPath.row。我需要更改toIndexPath.row的值。更新值核心數據
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath
*)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
if (fromIndexPath.section == toIndexPath.section) {
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"MyBase"
inManagedObjectContext:self.objectContext];
[fetchRequest setEntity:entityDescription];
empArray = [(NSArray*)[self.objectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
MyBase *employee = [empArray objectAtIndex:fromIndexPath.row];
[empArray removeObjectAtIndex:fromIndexPath.row];
[empArray insertObject:objectToMove atIndex:toIndexPath.row];
}
}