如何将我的地址簿数据放入 UITextField
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
谢谢您的帮助
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;
Thats my code now i need assistance with what to import && how would i set my UITextView as that
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码将姓名和电话号码放入
_allItems
数组中,您随后可以使用该数组填充文本视图:假设您连接了一个名为
mytextview< 的
UITextView
/代码>。This code puts name and phone number in the
_allItems
array, which you can subsequently use to fill a textview with:assuming you have a
UITextView
hooked up namedmytextview
.