如何将我的地址簿数据放入UITextField

时间:2010-07-18 09:30:23

标签: iphone objective-c abpeoplepickerview

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 stringWithFormat@"%@:%@",compositeName,phone];
        [compositeName release];
        [_allItems addObject:field];
    }
    [phoness release];
}
CFRelease(_addressBookRef);
[allPeople release];
allPeople = nil;

现在我的代码我需要帮助导入什么和&&我将如何设置我的UITextView

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

此代码将姓名和电话号码放在_allItems数组中,您随后可以使用该数组填充文本视图:

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

假设您有UITextView个名为mytextview的连接符。