使用NSArrayController划分NSTableView [英] Sectioned NSTableView using NSArrayController

查看:356
本文介绍了使用NSArrayController划分NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 NSArrayController 和可可绑定创建一个区段 NSTableView 我正在寻找一个类似的方法,如 NSFetchedResultsController 在iOS中,您可以设置一个区域的关键路径。我想做一个类似 NSArrayController

I'm trying to create a sectioned NSTableView using NSArrayController and cocoa bindings. I'm searching for a similar approach like with NSFetchedResultsController in iOS, where you can set a section key path. I want to make something similar with NSArrayController.

我给你一个例子:
我有不同任务。每个任务具有三个不同的优先级中的一个,低,中或高。任务还具有标题,描述,日期等属性。我想按优先级分区或分组任务(这里的关键路径是优先级)。

I give you an example: I have different tasks. Each task has one of three different priorities, low, medium or high. The tasks also has attributes like title, description, date, etc. I want to section or group the tasks by priority (the section key path here is the priority).

你可以用绑定和 NSArrayController 解决这个问题吗?我需要多个 NSArrayController 或只有一个?

You can I solve this problem with bindings and NSArrayController? Do I need multiple NSArrayController or just one?

推荐答案

c $ c> NSTableView 可以渲染组行,不幸的是它依赖于委托或数据源来展开层次结构。它不理解 UITableView UITableViewStyleGrouped 这样的替代数据源语义,也不了解 NSArrayController 具有 NSFetchedResultsController 的区段方法的等价物。

Though NSTableView can render group rows, unfortunately it depends on the delegate or data source to flatten the hierarchy. It doesn't understand alternate data source semantics like UITableView's UITableViewStyleGrouped, nor does NSArrayController have equivalents to NSFetchedResultsController's section methods.

一个选项是 NSOutlineView 它是为显示任意深层次数据而设计的,但它可能创建比简单两级结构所需的更多工作。 (您可以将大纲视图绑定到 NSTreeController ,但树控制器记录不良,并且启动时设计不当。)

One option is NSOutlineView which is designed for displaying arbitrarily deep hierarchical data, but it probably creates more work than necessary for a simple two-level structure. (You can bind an outline view to NSTreeController but the tree controller is poorly documented, and to boot, it's badly designed.)

所以,这里是我的建议:

So, here's what I suggest:


  • 编写自己的控制器类,实现 NSTableViewDelegate NSTableViewDataSource

  • 使用单个数组控制器按优先级排序, 从中返回 tableView:isGroupRow:

  • Write your own controller class which implements NSTableViewDelegate and NSTableViewDataSource.
  • Use a single array controller which sorts by priority, and write your own code to offset the row indexes to accommodate the section headings.
  • Return YES from tableView:isGroupRow: on the section headings.
  • Don't use bindings for this one.

您可以使用绑定也可以从第三方寻找可重用的,具有绑定功能的控制器。

You could also look for a reusable, bindings-capable controller from a third party.

这篇关于使用NSArrayController划分NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆