我试图让用户创建一个新的联系人。虽然我的屏幕提示用户输入他的所有细节,但顶部没有导航栏(就像默认的Apple联系人应用程序一样)。没有办法离开现场。我使用的是ContactUI框架中的Speed2.0和Xcode 7.3。下面是代码:
// 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)
}以下是我想要得到的:苹果默认
以下是我所拥有的:我所拥有的
我将从选项卡视图控制器中的动作表启动新的联系人视图控制器。我尝试将选项卡嵌入到导航视图控制器中,但没有效果。我甚至尝试过设置setToolbarHidden属性的navController,但没有帮助。
谢谢你的帮助。我在其他论坛上看到了这个问题,但它们没有帮助。
发布于 2016-05-23 12:22:00
视图控制器必须嵌入到UINavigationController中,您应该推送或显示视图控制器:
navigationController?.pushViewController(contactPicker, animated: true)而不是呈现视图控制器
发布于 2016-09-27 10:10:43
您必须将contactViewController嵌入到UINavigationController中,并实现委托方法。
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
}发布于 2016-05-23 12:20:01
由于您在当前活动控制器之上显示contactPicker视图控制器,您将无法访问导航栏,因为视图是完全呈现的,如果您想要像苹果联系人应用程序中的按钮一样,需要将呈现视图控制器嵌入到UINavigationController中,并添加左、右栏按钮项。
请参考下面的苹果示例,它演示了相同的示例。m.html
https://stackoverflow.com/questions/37390406
复制相似问题