ABPersonViewController不显示除了名称的属性

来源:互联网 发布:linux crontab 权限 编辑:程序博客网 时间:2024/05/16 10:41

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

up vote1down votefavorite
1

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];}
shareimprove this question
 

4 Answers

activeoldestvotes
up vote0down voteaccepted

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.

shareimprove 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
up vote3down vote

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.


0 0
原创粉丝点击