- (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
网友评论