更改contactsUI'forNewContact'swift

时间:2016-08-03 10:29:09

标签: ios swift uinavigationcontroller swift3 cncontact

我正在使用联系人UI添加此代码的新联系人

        let a = CNContact()
        let contactPickerViewController = CNContactViewController.init(forNewContact: a) // iOS Editor
        contactPickerViewController.delegate = self
        let nav = UINavigationController.init(rootViewController: contactPickerViewController)
        nav.title = "AppContact"
        self.present(nav, animated: true, completion: nil)

我想将导航栏标题设为“AppContact”,但它始终获得默认的“新建联系人”。如何更改标题?

1 个答案:

答案 0 :(得分:2)

导航栏从目前位于导航堆栈顶部的UIViewController抓取标题,在您的情况下为RootViewController。而是更改UIViewController

的title属性
    let a = CNContact()
    let contactPickerViewController = CNContactViewController.init(forNewContact: a) // iOS Editor
    contactPickerViewController.delegate = self
    let nav = UINavigationController.init(rootViewController: contactPickerViewController)
    contactPickerViewController.title = "AppContact" //Using currently presented ViewController .title property.
    self.present(nav, animated: true, completion: nil)

这是对Apple提供的title类引用的UIViewController属性的讨论

讨论:

Set the title to a human-readable string that describes the view. If the view controller has a valid navigation item or tab-bar item, assigning a value to this property updates the title text those objects.

LinkUIViewController标题文档。