2016-04-29 10 views
1

Wie kann ich den Kontakt in der Tabellenansicht anzeigen?Ich habe den Kontakt mit Hilfe von cncontacts geholt und kann sie auf dem Konsolenbildschirm anzeigen, aber nicht in der Tabellenansicht

Ich habe die Kontakte über 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); 
     } 
    }]; 
} 

Jede Hilfe geschätzt wird geholt.

+0

Sie haben Tableview neu zu laden, nachdem Kontakte bekommen –

+0

ja ich es versucht habe. ..aber noch nicht in der Lage ... in Hauptthread Kontaktnamen auf Tabellenansicht –

+0

reload-Tabelle anzuzeigen 'dispatch_async (dispatch_get_main_queue()^{ [tblview reload]; });' –

Antwort

1

Sie benötigen Daten auf Haupt-Thread neu zu laden, wenn der Abruf Kontakt von CNContact abgeschlossen ist

auf Haupt-Thread laufen

dispatch_async(dispatch_get_main_queue(), ^{// reload your table here 
}); 
+0

Danke nochmal für Ihre Hilfe Herr ... es hat für mich funktioniert. –