我正在使用联系人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”,但它始终获得默认的“新建联系人”。如何更改标题?
答案 0 :(得分: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)
这是对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.
Link至UIViewController
标题文档。