【问题标题】:NSArrayController+cocoa binding + core data: get the selected row at application LaunchingNSArrayController+cocoa 绑定+核心数据:在应用启动时获取选中的行
【发布时间】:2013-03-11 11:18:06
【问题描述】:

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

【问题讨论】:

  • 所以arrangedObjects 返回结果但selectedObjects 不返回?

标签: macos cocoa-bindings nsarraycontroller


【解决方案1】:

您必须在 applicationDidFinishLaunching: 中的 ArrayController 上进行提取才能在此处查看您的实体。在从 ArrayController 访问任何内容之前尝试这样做:

 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
     NSError *error;
     [arrayManager fetchWithRequest:nil merge:NO error:&error];
     Entity *ent = arrayManager.arrangedObjects[0];
 }

【讨论】:

  • 那是工作谢谢你,你能解释一下为什么我要在一个 nil 工作请求的情况下进行 fech 吗?
  • 当然。据我所知,传递 nil 只是执行 NSArrayController 的默认请求。我可能是错的,但这正是我所看到的让它执行它在其他地方加载时执行的默认请求。 - 此外,从技术上讲,您在执行请求时应该进行一些错误处理。 fetchWithRequest:merge:error 返回一个 BOOL。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-08
  • 1970-01-01
相关资源
最近更新 更多