我有一个集合视图,其中一些单元格代表一个联系人(他们的数据有一个电话号码和姓名),我正在尝试将联系人添加到 iPhone 联系人中。我从CollectionViewCell
导航控制器内部的一个名为“添加联系人”的按钮创建了一个 segue,并将其标识符设置为“ADD_CONTACT”。
在情节提要中,我的 segue 有一个没有根视图控制器的导航控制器。在prepareToSegue
委托我的视图控制器中,UICollectionView
我编写了以下代码:
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)
}
}
}
}
这会导致黑屏。如何解决这个问题?我想看看CNContactViewController