[英]CNContactViewController - Edit button not showing up
I'm currently working on a Swift app and I want the user to be able to edit a contact that they created earlier in the app. 我目前正在使用Swift应用程序,希望用户能够编辑他们先前在该应用程序中创建的联系人。 That being said, I'm using the CNContactViewController(forContact: CNContact)
init function to create the view controller. 就是说,我正在使用CNContactViewController(forContact: CNContact)
初始化函数来创建视图控制器。
I have the following code in a subclass of TableViewController
which is embedded in a Navigation controller 我在嵌入在导航控制器中的TableViewController
的子类中有以下代码
let contactViewController = CNContactViewController(forNewContact: contact)
contactViewController.delegate = self
self.navigationController?.pushViewController(contactViewController, animated: true)
When the contactViewController
comes into view, the contact loads fine but the edit button is missing from the Navigation bar on top. 当contactViewController
进入视图时,联系人会很好地加载,但是顶部的导航栏中缺少编辑按钮。 If I hard code print(contactViewController.allowsEdits)
immediately before pushing it to the Nav controller, it says true, which is weird. 如果我在将其推送到Nav控制器之前立即对print(contactViewController.allowsEdits)
硬编码,则它表示true,这很奇怪。
Thanks for the help. 谢谢您的帮助。
(Note, the contact I pass into the constructor is a CNMutableContact
, so it should be editable) (请注意,我传递给构造函数的联系人是CNMutableContact
,因此它应该是可编辑的)
You should add only this to appear the 'Edit' button before pushing your contactViewController: 在按下contactViewController之前,您应该仅添加此内容以显示“编辑”按钮:
let contactViewController = CNContactViewController(forNewContact: contact)
contactViewController.delegate = self
//Here you make Edit button to appear and do things that it is supposed to do
contactViewController.navigationItem.rightBarButtonItem? = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Edit,target: self, action: nil)
self.navigationController?.pushViewController(contactViewController, animated: true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.