我在数组中有 iOS 联系人。当用户使用键盘更改文本时,我需要在此数组上执行搜索,但如果联系人超过 500,则键盘会关闭。
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
[self doPerformSearchingInContacts:substring];
dispatch_sync(dispatch_get_main_queue(), ^{
[self displaySearchedFriendResult];
});
});
// Function for searching
-(void) doPerformSearchingInContacts:(NSString*) serachStr {
self.filterDeviceContact = nil;
NSMutableArray *people = [NSMutableArray array];
[people addObjectsFromArray:self.deviceContact];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@",serachStr];
self.filterDeviceContact = [people filteredArrayUsingPredicate:predicate];
NSLog(@"self.filter %@ ",self.filterDeviceContact);
}
谢谢!