1
連絡先をテーブルビューで表示するにはどうすればいいですか?私はcncontactsを使用して連絡先を取り出し、コンソール画面に表示できますが、テーブルビューでは表示できません
は私がCNContactStore iOSの9
- (void) getContacts {
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES) {
//keys with fetching properties
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey,CNContactImageDataKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
NSArray *cnContactsarray = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keys error:&error];
if (error) {
NSLog(@"error fetching contacts %@", error);
}
else {
for (CNContact *contact in cnContactsarray) {
//store all the contacts as per your requirement
NSLog(@"Name : %@",contact.givenName);
NSLog(@"Id : %@",contact.identifier);//the contact id which you want
[_ContactsCN addObject:contact];
}
}
NSLog(@"array %@",_ContactsCN);
}
}];
}
任意の助けが理解されるであろう経由で連絡先をフェッチしています。メインスレッドで実行する
あなたが連絡先 –
はい私はそれを試してみましたを取得した後、テーブルビューをリロードする必要があります。 ..でも、テーブルビューの連絡先名を表示することができない –
メインスレッドのリロードテーブル... 'dispatch_async(dispatch_get_main_queue()、^ { [tblview reloadData]; });' –