UITableView加载到内容缓慢的iOS中

时间:2019-06-12 12:51:13

标签: ios objective-c uitableview contacts

我有一个应用程序,在其中我过滤了已实现功能的重复联系人,但问题是联系人数越来越少,因为联系人的加载速度也变慢,因此很快。 下面是我正在使用的代码块

-(void)loadDuplicateContacts{


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        [addressBook loadContacts:^(NSArray<APContact *> * _Nullable contacts, NSError * _Nullable error) {

            NSMutableArray *duplucateDataArray = [[NSMutableArray alloc] init];
            duplucateDataArray = [contacts mutableCopy];
            duplicateContactsArray = [[NSMutableArray alloc] init];
            duplicateContactsDictinary = [[NSMutableDictionary alloc] init];
            self.dictionaryKeys = [NSArray new];
            for (APContact *contact in duplucateDataArray) {
                NSMutableArray *countArray = [[NSMutableArray alloc] init];
                [duplucateDataArray enumerateObjectsUsingBlock:^(APContact *obj, NSUInteger idx, BOOL *stop)
                 {

                     if ([JustNumber([obj.phones[0] number]) isEqualToString:JustNumber([contact.phones[0] number])])
                     {

                         [countArray addObject:contact.name.compositeName];

                     }
                 }];

                if (countArray.count > 1) {

                    if (duplicateContactsDictinary[JustNumber([contact.phones[0] number])]) {
                        NSMutableArray  *retriveArray = [[NSMutableArray alloc] init];
                        retriveArray = [duplicateContactsDictinary objectForKey:JustNumber([contact.phones[0] number])];
                        [retriveArray addObject:contact];
                        [duplicateContactsDictinary setObject:retriveArray forKey:JustNumber([contact.phones[0] number])];

                    }else{
                        NSMutableArray *contactCreationArray = [[NSMutableArray alloc] init];
                        [contactCreationArray addObject:contact];
                        [duplicateContactsDictinary setObject:contactCreationArray forKey:JustNumber([contact.phones[0] number])];

                    }
                    [duplicateContactsArray addObject:contact];

                }

            }

            dispatch_async(dispatch_get_main_queue(), ^(void) {
                [self.tableView reloadData];
            });

        }];
    });

}

任何建议都会更有帮助

0 个答案:

没有答案