我必须通过引入搜索关键字并在运行时过滤来过滤一组对象。我该怎么做?
//this is my Article class
@property int intID;
@property (nonatomic, strong) NSString *strName;
@property (nonatomic, strong) NSString *strTitle;
@property (nonatomic, strong) NSString *strDescription;
@property (nonatomic, strong) NSString *lang;
@property (nonatomic, strong) NSString *dateDate;
@property (nonatomic, strong) NSData *dataPicture;
@property (nonatomic, strong) NSString *link;
@property (nonatomic, strong) NSString *gallery;
@property int flag;
@property int subcat;
@property int cat;
@property int idpic;
我必须选择包含带有引入字符串的文本的文章
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"strName MATCHES '.*(%@).*'", searchText];
NSLog(@"%@", [NSString stringWithFormat:@"strName MATCHES '.*%@.*' OR strTitle MATCHES '.*%@.*'", searchText, searchText]);
articleSearchArray=[NSMutableArray array];
articleSearchArray = [NSMutableArray arrayWithArray:[allArticleArr filteredArrayUsingPredicate:predicate]];
for(Article *article in articleSearchArray)
{
NSLog(@"Article id is %i", article.intID);
}
[mytableView reloadData];
}