开发者

How to create a iTunes style source list that filters a main table view?

开发者 https://www.devze.com 2023-02-21 06:43 出处:网络
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.

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 sele开发者_JS百科cting 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?


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'
0

精彩评论

暂无评论...
验证码 换一张
取 消