在一個一對多的關係進行細胞reodering我學習coreData
,我新,我已經創建了一個一個一對多的老闆和員工,(即一個老闆的關係,許多員工)。所以我在firstTableView
上顯示了所有老闆,當用戶點擊單元格時,他可以查看分配給每個老闆的員工,還可以將員工添加到任何特定的老闆。 現在我想重新排序老大牢房。那麼應該怎麼做呢?如何CoreData
基於以下
- (void)insertNewObject:(NSString *)fileName
{
Boss *bossName = [NSEntityDescription insertNewObjectForEntityForName:@"Boss" inManagedObjectContext:self.managedObjectContext];
[bossName setName:fileName];
NSManagedObject *lastObject = [self.controller.fetchedObjects lastObject];
float lastObjectDisplayOrder = [[lastObject valueForKey:@"displayOrder"] floatValue];
NSLog(@"%f",lastObjectDisplayOrder);
[bossName setValue:[NSNumber numberWithDouble:lastObjectDisplayOrder + 1.0] forKey:@"displayOrder"];
// Save the context.
NSError *error = nil;
if (![self.managedObjectContext save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
任何人都可以幫助我在這方面 – Ranjit