我目前在ABAddressBookGetPersonWithRecordID方面遇到困难。我保存了一个ID,然后试图再次调用它。
目前我正在做一些简单的测试来测试链接,但它并没有起作用。
首先,我可以使用以下方法从我的iPhone模拟器地址簿中读取对象:
-(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来调用此联系人信息。我目前正在尝试这样做:
-(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
因此,我得到的只是一个空人。我做错了什么?我完全不知道!
问候,@norskben