ABPersonViewController不显示除了名称的属性

转自:http://stackoverflow.com/questions/5013349/why-doesn-t-abpersonviewcontroller-show-any-properties-besides-the-name

For some reason, ABPersonViewController is unwilling to display any properties aside from the name, no matter what properties are set for it to display.

I’m unable to use the AddressBookUI controllers to let a user select a contact to display, since my UI has custom requirements, otherwise I’d go that route (as Apple does in their sample project.)

Here’s the code that doesn’t work — am I missing something?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // ABContact is of my own creation
    ABContact *contact = [self contactAtIndexPath: indexPath];
    ABPersonViewController *viewController = [[ABPersonViewController alloc] init];

    // This returns a valid ABRecordRef, as indicated by the fact that the 
    // controller does display the name of this contact when it is loaded
    viewController.displayedPerson = contact.record;

    // Copied directly from Apple’s QuickContacts sample project
    NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], 
                               [NSNumber numberWithInt:kABPersonEmailProperty],
                               [NSNumber numberWithInt:kABPersonBirthdayProperty], nil];

    viewController.displayedProperties = displayedItems;

    [self.navigationController pushViewController: viewController animated: YES];
    [viewController release];
}
share improve this question
 

4 Answers

up vote 0 down vote accepted

The value of these constants is undefined until one of the following functions has been called: ABAddressBookCreate, ABPersonCreate, ABGroupCreate.

The above is come from apple document. I think those property constants are not valid for above reason.

share improve this answer
 
 
What part of "valid ABRecordRef" wasn't clear in my question? I hate to be snarky, but did you even read my sample code? –   Abraham Vegh  Feb 16 '11 at 11:41
 
Well, good luck to you. I encountered a problem before, because above reason I said, but apparently it is impossible for your case. –   Toro  Feb 16 '11 at 12:45
 
It appears that apple removed this warning from current documentation :-( –   Adrian  Nov 29 '12 at 16:15

ABContact is from Erica Sadun's ObjC wrapper (ABContactsHelper), right?

I'm using it too and found that for some reason, Apple's ABPersonViewController somehow treats supplied ABRecordRef as contact.record differently than if you directly use C functions. Thus this:

ABContact *person = ...;
ABPersonViewController *personVC = ...;
personVC.displayedPerson = person.record;

will load almost nothing into the controller. Sometimes first/last name, sometimes not even that. However, if you do this:

ABContact *person = ...;
ABPersonViewController *personVC = ...;
ABAddressBookRef addressBook = ABAddressBookCreate();
personVC.displayedPerson = ABAddressBookGetPersonWithRecordID(addressBook, person.recordID);

then it will load everything.

Previous answer says that ABAddressBookCreate is required for the constants to have a value, but this is already done in [ABContactsHelper addressBook] call (first thing I call in my code). This it's really puzzling where it gets lost. But the previous does work, consistently.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值