我的模型长这样:
这将生成一个类似于大纲视图的外观:
正如您所看到的,当子项应该仅出现在根项下时,我正在获取子项的重复条目。
我做错了什么?
示例项目位于 sample project link。
谢谢。
- (void) addChildWithName:(NSString*)name toParent:(Item*)parent
{
static NSUInteger count = 1;
Item* childItem;
childItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:[self managedObjectContext]];
[childItem setName:[NSString stringWithFormat:@"%@ %lu", name, count]];
[childItem setParent:parent];
count++;
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
Item* rootItem;
rootItem = [NSEntityDescription insertNewObjectForEntityForName:@"Item" inManagedObjectContext:[self managedObjectContext]];
[rootItem setName:@"rootItem"];
[self addChildWithName:@"rootChild" toParent:rootItem];
[self addChildWithName:@"rootChild" toParent:rootItem];
[self addChildWithName:@"rootChild" toParent:rootItem];
[self addChildWithName:@"rootChild" toParent:rootItem];
[self addChildWithName:@"rootChild" toParent:rootItem];
}
这将生成一个类似于大纲视图的外观:
正如您所看到的,当子项应该仅出现在根项下时,我正在获取子项的重复条目。
我做错了什么?
示例项目位于 sample project link。
谢谢。