iphone地址簿 - 在ABAddressBookGetPersonWithRecordID中获取null项 [英] iphone addressbook - getting null item in ABAddressBookGetPersonWithRecordID
问题描述
此刻我正在努力克服ABAddressBookGetPersonWithRecordID。我正在保存一个ID,然后再次尝试重新调用它。
目前我正在做一些简单的测试链接,但它无法正常工作。
I'm really struggling with ABAddressBookGetPersonWithRecordID at the moment. I am saving an ID, and then trying to call it back up again. Currently im doing something simple to test the linking, but its not working.
首先,我可以使用以下方式从我的iphone模拟器地址簿中读取对象:
First, I can read objects from my iphone simulator address book using:
-(BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString *contactName;
NSString *contactCompany;
NSString *contactFirst;
NSString *contactLast;
contactFirst = [(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) stringByAppendingString:@" "];
contactLast = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
contactName = [contactFirst stringByAppendingString:contactLast];
contactCompany = (NSString *)ABRecordCopyValue(person, kABPersonOrganizationProperty);
NSNumber *recordId = [NSNumber numberWithInteger: ABRecordGetRecordID(person)];
NSLog(@"record id is %d", recordId);
NSLog(@"Person Reference: %d", person);
NSLog(@"Name: %@", contactName);
NSLog(@"Company: %@", contactCompany);
哪个有NSLog:
2010-01-26 11:52:31.396 SQL[19786:207] record id is 69283952
2010-01-26 11:52:31.397 SQL[19786:207] Person Reference: 69495792
2010-01-26 11:52:31.398 SQL[19786:207] Name: John Adams
2010-01-26 11:52:31.398 SQL[19786:207] Company: (null)
所以我推测这一切都是为了这一切。问题是使用'记录ID'69283952来重新调用此联系信息。
我目前正在尝试这样做:
So my presumption is that it all works on that end. The problem is using the 'record id' 69283952, to call this contact info back up. I am currently trying to do it like this:
-(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)newindexPath {
ABAddressBookRef ab = ABAddressBookCreate();
ABPersonViewController *pvc = [[ABPersonViewController alloc] init];
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab,69283952);
NSLog(@"person - %d", person);
pvc.displayedPerson = person;
NSLog(@"pvc.displayedPerson - %d", pvc.displayedPerson);
pvc.addressBook = ab;
pvc.allowsEditing = YES;
pvc.personViewDelegate = self;
[[self navigationController] pushViewController:pvc animated:YES];
[pvc release];
哪个有NSLog
2010-01-26 11:58:19.393 SQL[19849:207] Looking Up Contact Now
2010-01-26 11:58:19.399 SQL[19849:207] person - 0
2010-01-26 11:58:19.400 SQL[19849:207] pvc.displayedPerson - 0
因此我得到的只是一个无效的人。我究竟做错了什么?我完全不知道!
And thus all i get is a null person. What am I doing wrong? I have absolutely no idea!
问候,@ norskben
regards, @norskben
推荐答案
NSNumber是一个对象,而不是整数。
NSNumber is an object, not an integer.
要将NSNumber对象插入格式字符串(例如NSLog),您应该使用%@(不是%d) 。
To insert an NSNumber object into a format string (such as for NSLog), you should use %@ (not %d).
NSNumber *recordId = [NSNumber numberWithInteger:ABRecordGetRecordID(person)];
NSLog(@"record id is %@",recordId);
同样,如果在NSNumber对象中有recordID,则可以使用<$获取整数值c $ c> integerValue :
Similarly, if you have the recordID in an NSNumber object, you can get the integer value using integerValue
:
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab,recordId.integerValue);
这篇关于iphone地址簿 - 在ABAddressBookGetPersonWithRecordID中获取null项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!