为什么 NSOutlineView 在我想在大纲视图中显示的 NSURL 对象上调用 -indexPath ?

发布于 2024-11-10 02:05:37 字数 907 浏览 3 评论 0原文

我有一个 NSOutlineView,我想用 NSURL 对象列表填充它。我在 NSTableView 中工作。作为转向 NSOutlineView 的第一步(以便我可以根据用户想要的各种标准对 NSURL 对象进行分组),我以模仿表视图的方式实现了 NSOutlineViewDataSource 协议的最小方法:

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
  if(!item) return [[self.resultsArrayController arrangedObjects] count];
  return 0;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
  if(!item){
    return [[self.resultsArrayController arrangedObjects] objectAtIndex:index];
  }
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
  return [item valueForKey:[tableColumn identifier]];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
  return NO;
}

这不断抛出无法识别的选择器异常,显示[NSURL indexPath] 正在被调用。任何人都知道为什么调用此方法或如何解决它?

I have an NSOutlineView that I want to populate with a list of NSURL objects. I have this working in NSTableView. As a first step toward moving to NSOutlineView (so that I can group the NSURL objects by various criteria as the user wants) I implemented the NSOutlineViewDataSource protocol's minimum methods in a way that should mimic the table view:

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
  if(!item) return [[self.resultsArrayController arrangedObjects] count];
  return 0;
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
  if(!item){
    return [[self.resultsArrayController arrangedObjects] objectAtIndex:index];
  }
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
  return [item valueForKey:[tableColumn identifier]];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
  return NO;
}

This keeps throwing an unrecognized selector exception showing [NSURL indexPath] is being called. Anyone have an idea why this method is being called or how to work around it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2024-11-17 02:05:37

我不确定这是否是您的情况,但当我将大纲的选择索引路径绑定到我的控制器时,我在 NSOutlineView 上遇到了同样的问题。之后,每次我选择一个项目时,NSOutlineView 都会尝试查询项目的 indexPath 方法。

我想这个绑定旨在与 NSTreeController 结合使用。至少当我有一个时它工作得很好。目前,我能找到的唯一解决方案是完全避免使用绑定或将其与 NSTreeController 一起使用。

I'm not sure it's your case, but I have faced the very same issue with the NSOutlineView when I binded the Selection Index Paths of the outline to the my Controller. After that NSOutlineView tried to query the indexPath method of the items every time I selected an item.

I suppose this binding is intended to be used in combination with the NSTreeController. At least it worked fine when I had one. At the moment, the only solution I can find is to avoid using the binding at all or use it with the NSTreeController.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文