I have a collection view with some cells representing a contact (their data has a phone number and name) and I am trying to add the contact to the iPhone contacts. I have created a segue from a button called "add contact" that is inside the CollectionViewCell to a navigation controller, and set its identifier as "ADD_CONTACT".
In the storyboard, my segue has a navigation controller with no root view controller.
in prepareToSegue of the view controller that delegates my UICollectionView I wrote this code:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == ADD_CONTACT {
        let dest = segue.destination as! UINavigationController
        if let cell = sender as? SBInstructionCell {
            if cell.isContact {
                let newContact = CNMutableContact()
                if let phone = cell.instructionBean?.contactAttachment?.phoneNumber{
                    newContact.phoneNumbers.append(CNLabeledValue(label: "home", value: CNPhoneNumber(stringValue: phone)))
                }
                if let name = cell.instructionBean?.contactAttachment?.contactName {
                    newContact.givenName.append(name)
                }
                let contactVC = CNContactViewController(forNewContact: newContact)
                contactVC.contactStore = CNContactStore()
                contactVC.delegate = self
                dest.setViewControllers([contactVC], animated: false)
            }
        }
    }
}
this results with a black screen.
How can this be fixed? I want to see the CNContactViewController 
 
                        
Eventually I solved this in a different approach using Closures.
In my
UICollectionViewCellI added this var:Now on my button's action in the same cell I have this func:
Which calls the function.
In my
CollectionViewin cell for item at index path, I set the closure like this:This worked perfectly. I learned that for navigating from a cell, it is best to use closures.