2010-07-18 53 views
0
ABAddressBookRef _addressBookRef = ABAddressBookCreate(); 
NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef); 
NSMutableArray* _allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing 
for (id record in allPeople) { 
    CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty); 
    NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty); 
    CFRelease(phoneProperty); 
    for (NSString *phone in phones) { 
     NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record); 
     NSString* field = [NSString [email protected]"%@:%@",compositeName,phone]; 
     [compositeName release]; 
     [_allItems addObject:field]; 
    } 
    [phoness release]; 
} 
CFRelease(_addressBookRef); 
[allPeople release]; 
allPeople = nil; 

那是我的代码,现在我需要什么进口& &会怎么设置我的UITextView为如何把我的地址簿数据导入的UITextField

感谢所有帮助

回答

1

此代码援助放_allItems阵列,您可以随后使用,以填补一个TextView与姓名和电话号码:

for (NSString *txt in _allItems) 
{ 
    mytextview.text = [mytextview.text stringByAppendingFormat:@"%@\n",txt]; 
} 

假设你有一个名为mytextviewUITextView

+0

以及我需要为通讯录添加什么标头,因为我正在输入许多引用错误:/ – user393273 2010-07-18 10:11:57

+0

grepping表示'#import '和/或'#import ' – mvds 2010-07-18 10:15:00