如何创建过滤主表视图的 iTunes 风格源列表?

发布于 2024-10-30 13:24:53 字数 375 浏览 2 评论 0原文

我读过一些关于如何模仿 iTunes 源列表样式的帖子。但我似乎无法弄清楚需要做什么才能让它们在主表视图中实际显示其他内容。

我的设置是这样的:我在后台有核心数据,其中包含 iTunes 中的所有曲目和具有 3 个状态的“状态”字符串。我只想在选择源列表中的项目时显示部分标题。源列表项与轨道的状态相匹配。 换句话说:3 个源列表项代表一个数据集中的 3 个不同组。这些组通过该状态变量进行区分。

我尝试创建一个 NSStrings 和 NSPredicates 数组,并将所选项目绑定到主表视图过滤谓词。但这没有用。

非常感谢您的回复。

编辑:现在可以从数组设置过滤谓词。但这对于过滤表的 NSSearch 字段来说效果不佳。还有其他方法或者我可以轻松组合这两个谓词吗?

I have read some threads about how to imitate the iTunes source list style. But I cannot seem to figure out what needs to be done to let them actually show other things in the main table view.

My setup is this: I have core data in the background containing all the tracks from iTunes and a "state" string that has 3 states. I want to only show parts of the titles on selecting an item in the source list. The source list items match the states of the tracks.
In other words: 3 source list items representing 3 different groups within one dataset. The groups are differentiated with this state variable.

I have tried to make an array of NSStrings and NSPredicates and bind the selected item to the main table views filtering predicate. But it did not work.

Thank you very much for your reply.

EDIT: Setting filter predicates from an array works now. But this does not play well with NSSearch fields that filter the table. Is there another way or can I combine the two predicates easily?

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

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

发布评论

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

评论(1

昔日梦未散 2024-11-06 13:24:53

您可以通过“OR”或“AND”将两个谓词“组合”在一起。换句话说,假设您有这两个谓词:

NSPredicate *one = [NSPredicate predicateWithFormat:@"foo = 42"];
NSPredicate *two = [NSPredicate predicateWithFormat:@"bar = 'abc'"];

您可以执行以下操作:

NSArray *subpredicates = [NSArray arraWithObjects:one, two, nil];
NSPredicate *both = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
//this is equivalent to: foo = 42 AND bar = 'abc'

或者

NSPredicate *both = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
//this is equivalent to: foo = 42 OR bar = 'abc'

You can "combine" two predicates by "OR"ing or "AND"ing them together. In other words, let's say you have these two predicates:

NSPredicate *one = [NSPredicate predicateWithFormat:@"foo = 42"];
NSPredicate *two = [NSPredicate predicateWithFormat:@"bar = 'abc'"];

You can do:

NSArray *subpredicates = [NSArray arraWithObjects:one, two, nil];
NSPredicate *both = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];
//this is equivalent to: foo = 42 AND bar = 'abc'

Or

NSPredicate *both = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates];
//this is equivalent to: foo = 42 OR bar = 'abc'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文