0

我在数组中有 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);

}

谢谢!

4

1 回答 1

0

您将要使用dispatch_async添加到主线程,否则它将被阻塞。

[self doPerformSearchingInContacts:substring];

dispatch_async(dispatch_get_main_queue(), ^{
    [self displaySearchedFriendResult];  
});
于 2013-11-01T01:58:42.397 回答