经过几个小时/几天的搜索和潜入示例项目,我得出结论,我只需要问.如果我将assetsView(IKImageBrowserView)直接绑定到IB实例,那么NSArrayController一切正常.
- (void) awakeFromNib
{
library = [[NSArrayController alloc] init];
[library setManagedObjectContext:[[NSApp delegate] managedObjectContext]];
[library setEntityName:@"Asset"];
NSLog(@"%@", [library arrangedObjects]);
NSLog(@"%@", [library content]);
[assetsView setDataSource:library];
[assetsView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
两者NSLogs都是空的.我知道我错过了什么......我只是不知道是什么.目标是最终允许使用谓词以编程方式过滤此视图的"库"的多个实例.现在我只是想让它显示"Asset"实体的所有行.
另外:如果我NSArrayController在IB中创建然后尝试记录[library arrangedObjects]或手动设置assetsView的数据源,我会得到相同的空结果.就像我之前说的那样,如果我绑定library.arrangedObjects到IB中的assetsView.content(IKImageBrowserView) - 具有相同的托管对象上下文和IB设置的相同实体名称 - 一切都按预期工作.
- (void) awakeFromNib
{
// library = [[NSArrayController alloc] init];
// [library setManagedObjectContext:[[NSApp delegate] managedObjectContext]];
// [library setEntityName:@"Asset"];
NSLog(@"%@", [library arrangedObjects]);
NSLog(@"%@", [library content]);
[assetsView setDataSource:library];
[assetsView reloadData];
}
Run Code Online (Sandbox Code Playgroud)