私は学んcoreData
でいて、それは初めてです。上司と従業員の 1 対多の関係(つまり、1 人の上司と多くの従業員) を作成しました。そのため、すべてのボスをfirstTableView
表示しています。ユーザーがセルをクリックすると、各ボスに割り当てられた従業員が表示され、特定のボスに従業員を追加することもできます。次に、ボス セルの順序を変更します。それで、それはどのように行われるべきですか?
以下の議論に基づいて編集
- (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();
}
}