我创建了一个带有tableView的viewController,并将唯一列的标识符设置为“name”。然后我创建了一个arrayController,将其绑定到NSManagedObjectContext
并设置了正确的实体名称。
当我现在加载viewController时,tableView会显示正确的行数。但不幸的是,单元格不包含键NSManagedObject
的{{1}} s值。
我需要在name
子类或viewController(tableViews viewController)中实现什么?
我想向您展示一些代码,但我不知道这里有什么用处,因为它更像是一个概念问题......所以我会在评论中发布代码。
更新
这是我用于将arrayController绑定到tableView:
的代码NSManagedObject
要检查tableView获取的内容,我添加了这一行(在添加名为“content”的属性之后):
[_tableView bind:NSContentBinding toObject:_arrayController withKeyPath:@"arrangedObjects.name" options:nil];
在setter中我得到一个包含[self bind:NSContentBinding toObject:_arrayController withKeyPath:@"arrangedObjects.name" options:nil];
个实例的数组。但是tableView仍然没有显示任何值......
答案 0 :(得分:0)
我最终使用了标准NSTableViewDataSource
协议:
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
return [[_arrayController arrangedObjects] count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
return [[[_arrayController arrangedObjects] objectAtIndex:row] valueForKey:[tableColumn identifier]];
}
我认为这是一个可靠的解决方案。我可能会被-bind:toObject:withKeyPath:options:
想法所迷恋。