iOS 模糊搜索
2017-05-07 本文已影响154人
程序猿小武
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(@"%@",searchText);
if (self.dataArr.count==0) {
return;
}
if (searchText.length) {
self.isSearch = YES;
[self.resultArr removeAllObjects];
NSPredicate *predicate;
predicate = [NSPredicate predicateWithFormat: @"shiche_nickname CONTAINS %@" ,searchText];
NSArray *temp = [self.dataArr filteredArrayUsingPredicate:predicate];
self.resultArr = [[NSMutableArray alloc] initWithArray:temp];
[self.messageTableView reloadData];
}else
{
self.isSearch = NO;
[self.messageTableView reloadData];
}
}
[NSPredicate predicateWithFormat: @"shiche_nickname CONTAINS %@" ,searchText]
shiche_nickname 是属性名
如果没有属性 用SELF