1

我正在使用可可绑定、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--> 没有选择行!为什么 ?

4

1 回答 1

5

您必须在 ArrayController 上进行 fetchapplicationDidFinishLaunching:才能在那里看到您的实体。在从 ArrayController 访问任何内容之前尝试这样做:

 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
     NSError *error;
     [arrayManager fetchWithRequest:nil merge:NO error:&error];
     Entity *ent = arrayManager.arrangedObjects[0];
 }
于 2013-03-12T13:27:48.910 回答