我正在使用cocoa-binding,NSArrayController和核心数据。 在启动之后,应用程序必须得到第一个项目,我在applicationDidFinishLaunching中尝试这个:
1. Entity *ent = arrayManager.arrangedObjects[0];
2. Entity *ent = arrayManager.selectedObjects[0];
--->错误说数组是空的。为什么?
我不明白的另一件事是,当应用程序出现时,在tableView中有一个选定的行,但是当我记录它时:
NSLog(@"selected row in applicationDidFinishLaunching = %li",self.TableViewController.tableView.selectedRow);
log: -1
- >没有选择行!为什么?
答案 0 :(得分:4)
您必须在applicationDidFinishLaunching:
中对ArrayController进行提取才能在那里查看您的实体。在从ArrayController访问任何内容之前尝试执行此操作:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSError *error;
[arrayManager fetchWithRequest:nil merge:NO error:&error];
Entity *ent = arrayManager.arrangedObjects[0];
}