2011-04-02 42 views
0

我已经阅读了一些关于如何模仿iTunes源列表样式的线索。但我似乎无法弄清楚需要做些什么来让他们在主表视图中实际显示其他内容。如何创建过滤主表视图的iTunes样式源列表?

我的设置是这样的:我在背景中包含核心数据,其中包含来自iTunes的所有曲目以及具有3个状态的“状态”字符串。我只想在选择源列表中的项目时显示部分标题。源列表项匹配轨道的状态。换言之:代表一个数据集内3个不同组的3个源列表项。这些组与这个状态变量是不同的。

我试图做一个NSString和NSPredicates的数组,并将选定的项绑定到主表视图过滤谓词。但它没有奏效。

非常感谢您的回复。

编辑:从数组设置过滤器谓词现在工作。但是这对于过滤表的NSSearch字段并不合适。还有另一种方法,或者我可以轻松地将两个谓词结合起来吗?

回答

1

你可以通过“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'