【发布时间】:2013-01-04 12:47:55
【问题描述】:
嘿,我想过滤一个 NSArray。在这个数组中有很多信息,如姓名、城镇、电话号码等。但有些城镇是数组的两倍或三倍。
我有房产,里面有一个小镇。
所以我只想要数组中与属性匹配的那些对象。
例如: 在阵列中的立场:
- 弗兰克,纽约,123456
- 奥利弗,纽约,123456
- 托马斯,波士顿,123456
当房产是纽约时,我想要 olny 对象 1 和 2。
有人知道我该怎么做吗?
这是我的代码:
NSString *filterString = newsArticle;
NSPredicate *prediacte = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"Ort == '%@'",filterString]];
newsTownArray = [news filteredArrayUsingPredicate:predicate];
当我来排队时:
cell.textLabel.text=[[newsTownArray objectAtIndex:indexPath.row] objectForKey:"Name"];
【问题讨论】:
标签: ios objective-c properties filter nsarray