我正在尝试让用户创建一个新联系人。虽然我有屏幕提示用户输入他的所有详细信息,但顶部没有导航栏(就像默认的 Apple Contacts 应用程序中一样)。没有办法退出现场。我在 swift 2.0 和 Xcode 7.3 中使用 ContactUI 框架。这是代码:
// create a new contact
let createNewActionHandler = {(action: UIAlertAction) -> Void in
let newContact = CNMutableContact()
let contactPicker = CNContactViewController(forNewContact: newContact)
contactPicker.delegate = self
contactPicker.navigationController?.setToolbarHidden(false, animated: false)
self.presentViewController(contactPicker, animated: true, completion: nil)
}
这是我想要得到的: Apple Default
这是我拥有的: What I have
我正在从选项卡 View Controller 中的操作表启动新的联系人 View Controller 。我尝试将选项卡嵌入导航 View Controller 中,但没有效果。我什至尝试设置 navController 的 setToolbarHidden 属性,但没有帮助。
感谢您的帮助。我在其他论坛上看到了这个问题,但他们没有帮助。
最佳答案
您必须将 contactViewController 嵌入到 UINavigationController 和实现委托(delegate)方法。
let createNewActionHandler = {(action: UIAlertAction) -> Void in
let newContact = CNMutableContact()
let contactPicker = CNContactViewController(forNewContact: newContact)
contactPicker.delegate = self
let navigation = UINavigationController(rootViewController: contactPicker)
self.presentViewController(navigation, animated: true, completion: nil)
}
//MARK: - Delegate
func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
viewController.dismissViewControllerAnimated(true, completion: nil)
}
func contactViewController(viewController: CNContactViewController, shouldPerformDefaultActionForContactProperty property: CNContactProperty) -> Bool {
return true
}
关于ios - 无法关闭 CNContactViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37390406/