开发者

How to put my address book data into UITextField

开发者 https://www.devze.com 2023-01-08 06:59 出处:网络
ABAddressBookRef _addressBookRef = ABAddressBookCreate (); NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
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开发者_JS百科(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;

Thats my code now i need assistance with what to import && how would i set my UITextView as that

Thanks for any help


This code puts name and phone number in the _allItems array, which you can subsequently use to fill a textview with:

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

assuming you have a UITextView hooked up named mytextview.

0

精彩评论

暂无评论...
验证码 换一张
取 消