Search code examples
xcodeuiviewcontrollerstoryboardaddressbook

Xcode "Add Contact" Button


I am trying to create an "add contact" button in Xcode that would bring the user to address book and add a Name, Phone Number, email, and address to the contact list after the user clicks on the button.

If I wanted to implement this feature, how would I go about doing so if I am using storyboard?


Solution

  • I recommend looking over this documentation for the ABNewPersonViewController class.

    The setup I would use is to setup an IBAction to your "Add Contact" button. The IBAction can create an instance of the New Person VC.

    If you need to predefine some of the fields for the new contact, you will need to create an ABRecordRef and set the properties you want to be in the new contact. Then set the New Person VC's displayedPerson property to this record.

    At the end of the method, you can call `[self.navigationController presentViewController: newPersonVC];

    This may be possible in a storyboard, but I have always found it easier to do in code.

    Hopefully this will help.