如何获得类似于 Spotlight 或 iTunes 的搜索功能?

发布于 2024-07-17 22:30:44 字数 119 浏览 5 评论 0原文

我有一个 NSTableView,其中包含一些填充数据的列。 如何设置可以根据特定列的内容过滤行的搜索栏? 我正在寻找使用 Finder 中的 Spotlight 或 iTunes 中的搜索栏可以按元数据过滤歌曲的类型。

I have an NSTableView that contains a few columns that are populated with data. How do I set up a search bar that can filter the rows based on the content of a specific column? I am looking for the type of thing that is done with Spotlight in the Finder or the search bar in iTunes that can filter songs by metadata.

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

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

发布评论

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

评论(2

贪恋 2024-07-24 22:30:44

“Spotlight”功能实际上是通过 SearchKit API 为您提供的,尽管对于像您所描述的简单情况, NSPredicate 可能是更好的选择。 如果有人感兴趣,我为 CocoaHeads 编写了一个 SearchKit 演示文稿,您可以获取看看这里

"Spotlight" capability is actually given to you with the SearchKit API, although for a simple case like what you're describing NSPredicate would probably be a better choice. If anyone's interested though, I wrote a SearchKit presentation for CocoaHeads you can take a look at here.

猛虎独行 2024-07-24 22:30:44

你的数据源可以由 NSArrayController 管理吗?

有 2 种标准方法。 第一种(Tiger 之前的)技术是子类化​​ NSArrayController,覆盖 ArrangeObjects。 第二个(Tiger 之后)是将 NSSearchField 的谓词绑定到 NSArrayController 的 filterPredicate。 无论哪种情况,都将视图属性绑定到控制器的 arrangedObject 键(例如,将“name”NSTableColumn 绑定到控制器的 arrangedObjects.name 键,并将 NSTableView 的内容绑定到 排列对象)。 您可能想阅读编写谓词

Can your data source be managed by NSArrayController?

There are 2 standard approaches. The first (pre-Tiger) technique is to subclass NSArrayController, overriding arrangeObjects. The second (post-Tiger) is to bind NSSearchField's predicates to the NSArrayController's filterPredicate. In either case, bind your view properties to the controller's arrangedObject key (e.g. bind the "name" NSTableColumn to the controller's arrangedObjects.name key and bind the NSTableView's content to arrangedObjects). You might want to read up on writing predicates.

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