3

I'm currently working on a Swift app and I want the user to be able to edit a contact that they created earlier in the app. That being said, I'm using the CNContactViewController(forContact: CNContact) init function to create the view controller.

I have the following code in a subclass of TableViewController which is embedded in a Navigation controller

let contactViewController = CNContactViewController(forNewContact: contact)
contactViewController.delegate = self
self.navigationController?.pushViewController(contactViewController, animated: true)

When the contactViewController comes into view, the contact loads fine but the edit button is missing from the Navigation bar on top. If I hard code print(contactViewController.allowsEdits) immediately before pushing it to the Nav controller, it says true, which is weird.

Thanks for the help.

(Note, the contact I pass into the constructor is a CNMutableContact, so it should be editable)

timisplump
  • 33
  • 4

1 Answers1

-1

You should add only this to appear the 'Edit' button before pushing your contactViewController:

let contactViewController = CNContactViewController(forNewContact: contact)
contactViewController.delegate = self

//Here you make Edit button to appear and do things that it is supposed to do
contactViewController.navigationItem.rightBarButtonItem? = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit,target: self, action: nil)

self.navigationController?.pushViewController(contactViewController, animated: true)
Tino
  • 1
  • 1