Search code examples
iphonecocoa-touchiosaddressbook

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];
}

Solution

  • 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.