3

I am developing address book app. When user selects a user from a contact list , I want to open that record directly in EDIT mode using ABPersonViewController instead of clickng Edit button of ABPersonViewController. How can I achieve this? Thanks

Daniel
  • 23,129
  • 12
  • 109
  • 154
iOSAppDev
  • 2,755
  • 4
  • 39
  • 77
  • did you have a look at this project- https://developer.apple.com/library/ios/#samplecode/QuickContacts/Listings/Classes_QuickContactsViewController_m.html#//apple_ref/doc/uid/DTS40009475-Classes_QuickContactsViewController_m-DontLinkElementID_6 – Jatin Apr 25 '12 at 12:58

3 Answers3

2

Just call setEditing after the view is displayed:

ABPersonViewController *ab = [[ABPersonViewController alloc] init];
ab.allowsEditing = YES;
// customize as you see fit
[self.navigationController pushViewController:ab animated:YES];
[ab setEditing:YES animated:NO];

I tried this on the iPad from within a popover controller and that works fine.

Z S
  • 7,039
  • 12
  • 53
  • 105
1

In fact ABNewPersonViewController looks exactly like ABPersonViewController in edit mode.

Sergey Skopus
  • 517
  • 1
  • 5
  • 7
  • Great solution! And you just change the ABNewPersonViewController.Title to whatever you like, rather than "New Contact". – TreeAndLeaf Oct 23 '15 at 06:47
-2

I accomplished the same by doing like this:

    ABRecordID personId = (ABRecordID)contact_ID;// if you want to edit a particular record and you're maintaining contact ID somewhere in your project.
    ABPersonViewController *contactVC = [[ABPersonViewController alloc] init];
    contactVC.personViewDelegate = self;// set your ViewController as delegate
    contactVC.allowsEditing = YES; //set NO if you don't wanna allow editing
    contactVC.displayedPerson = ABAddressBookGetPersonWithRecordID(addressBook, personId);
    [self.navigationController presentViewController:contactVC animated:YES completion:nil];
Prakash
  • 605
  • 6
  • 16