views:

780

answers:

1

My app needs to associate instances of a custom class with contact records in the iPhone's AddressBook. Everything's all well and good when I present the ABPeoplePickerNavigationController and allow the user to pick an existing contact. Problem is there's no obvious way to allow a user to easily ADD a contact record if the one they're looking for doesn't already exist in their AddressBook.

How are people getting from ABPeoplePickerNavigationController to ABNewPersonViewController in a way that's easy & intuitive for the user?

+1  A: 

Hi,

it appears that it is not possible to add a new contact directly from the ABPeoplePickerNavigationController. Therefore, when the user clicks an add button, I am presenting an UIActionSheet with two buttons:

- (void) addContact{

    contactMenu = [[UIActionSheet alloc] 
            initWithTitle: nil 
            delegate:self
            cancelButtonTitle:@"Cancel"
            destructiveButtonTitle: nil
            otherButtonTitles:@"Select a contact", @"Add a new contact", NULL];

    [contactMenu showInView:self.view];

}

Here is the associated delegate method:

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{



     if(buttonIndex == 0){
      // select an existing contact 
      ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
      peoplePicker.peoplePickerDelegate = self;
      [self presentModalViewController:peoplePicker animated:YES];

     }

     if(buttonIndex == 1){

      // add a new contact
      ABNewPersonViewController *newPersonViewController = [[ABNewPersonViewController alloc] init];
      newPersonViewController.newPersonViewDelegate = self;

      UINavigationController *personNavController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
      [self presentModalViewController:personNavController animated:YES];

      [personNavController release];
      [newPersonViewController release];

     }

            if(buttonIndex == 2){
     // cancel the operation
     [actionSheet dismissWithClickedButtonIndex:2 animated:YES];
    }


}
unforgiven
you're missing a "[peoplePicker release];" under your (buttonIndex == 0)
Meltemi