更改 contactsUI 的标题 'forNewContact' swift

change title for contactsUI 'forNewContact' swift

我正在使用联系人 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",但它总是使用默认值 "New Contact"。如何更改标题?

导航栏从目前位于导航堆栈顶部的 UIViewController 获取标题,在您的例子中是 RootViewController。改为更改 UIViewController

的标题 属性
    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)

这是苹果

提供的UIViewControllerclass参考文献title属性的讨论

讨论:

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 标题文档。