我正在尝试使用内置的新联系人界面,并使用“取消”按钮获得意想不到的行为。下面的代码工作并调用新的联系人屏幕,但是取消按钮只会清除屏幕条目,而不是从新的联系人屏幕中取消。在内置的联系人应用程序中,点击cancel返回到联系人列表屏幕。我想要取消按钮关闭窗口。
@IBAction func newTwo(sender: AnyObject) {
AppDelegate.getAppDelegate().requestForAccess { (accessGranted) -> Void in
if accessGranted {
let npvc = CNContactViewController(forNewContact: nil)
npvc.delegate = self
self.navigationController?.pushViewController(npvc, animated: true)
}
}
}发布于 2016-03-18 01:01:22
您实现了CNContactViewControllerDelegate方法吗?这是指向文档的链接
例如:
func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
self.dismissViewControllerAnimated(true, completion: nil)
}发布于 2018-05-21 21:10:00
它使用以下代码对我有效:
Swift 3
func contactViewController(_ vc: CNContactViewController, didCompleteWith con: CNContact?) {
vc.dismiss(animated: true)
}另外,我改变了调用控制器的方式:
而不是:
self.navigationController?.pushViewController(contactViewController, animated: true)解决办法是:
self.present(UINavigationController(rootViewController: contactViewController), animated:true)我使用由编程-iOS-图书-示例编写的示例代码马特·纽堡找到了解决方案。
发布于 2017-02-14 07:28:27
做解雇的更好的方法是检查联系人是否为零,然后驳回它。如果您已将视图控制器从导航控制器中推送,则取消操作将不起作用。您可能必须执行以下操作:
func contactViewController(viewController: CNContactViewController, didCompleteWithContact contact: CNContact?) {
if let contactCreated = contact
{
}
else
{
_ = self.navigationController?.popViewController(animated: true)
}
}https://stackoverflow.com/questions/36073064
复制相似问题