2

我正在使用联系人 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”,但它总是得到默认的“新联系人”。如何更改标题?

4

1 回答 1

2

导航栏从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)

这是来自苹果提供的类引用的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.

链接UIViewController标题文档。

于 2016-08-03T10:43:45.823 回答