0

I have used ABNewPersonViewControllerDelegate in my project.It pops up new view for adding contact.

-(IBAction)Click:(id)sender
{
    ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
    view.newPersonViewDelegate = self;

    UINavigationController *newNavigationController = [[UINavigationController alloc]
                                                       initWithRootViewController:view];
    [self presentModalViewController:newNavigationController
                            animated:YES];
}

How to handle cancel and done button?.any example code will be appreciated.thanks in advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2681789
  • 895
  • 2
  • 9
  • 16

2 Answers2

3

If you read the documentation, you will find that the ABNewPersonViewControllerDelegate method newPersonViewController:didCompleteWithNewPerson: returns NULL for the person argument if cancel is pressed.

ColinE
  • 68,894
  • 15
  • 164
  • 232
1
(void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person{

    if (person != nil) {

        [self.tableview reloadData];
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

This the code I'am using. If the user hits the cancel button the picker returns the null ABRecordRef, so we have to check if picker have returned us the record or nil value and proceed further as desired.

bummi
  • 27,123
  • 14
  • 62
  • 101
Devang Tandel
  • 2,988
  • 1
  • 21
  • 43