2

我正在更新一個很久以前開始工作的舊Xcode項目。我將部署目標更新爲iOS 10.0,因此我不得不用Contacts框架替換ABAddressBook框架。我曾經在容器視圖中呈現ABPeoplePickerNavigationController,這是UINavigationController的根視圖控制器的子視圖。這樣我就能夠在導航控制器中呈現People Picker UI,該導航控制器位於標籤欄控制器內部(這意味着頂部的導航欄和底部的標籤欄仍顯示在人員選擇器UI周圍)。我用這個代碼(稱爲viewWillAppear導航控制器的根視圖控制器的做到這一點:在容器視圖中顯示CNContactPickerViewController?

let peoplePickerNavController:ABPeoplePickerNavigationController = ABPeoplePickerNavigationController() 
    self.addChildViewController(peoplePickerNavController) 
    peoplePickerNavController.didMove(toParentViewController: self) 
    peoplePickerNavController.navigationBar.removeFromSuperview() 
    peoplePickerNavController.view.frame = self.peoplePickerContainerView.bounds 
    peoplePickerNavController.view.translatesAutoresizingMaskIntoConstraints = true 
    peoplePickerNavController.peoplePickerDelegate = self 
    self.peoplePickerContainerView.addSubview(peoplePickerNavController.view) 

有了這個代碼,它仍然會在頂部導航控制器的導航欄完全顯示地址簿和我試圖用CNContactPickerViewController做同樣的事情,但是我遇到了這個問題,當我做同樣的事情時,我使用了導航控制器,它不會給我任何錯誤,但視圖控制器不會被顯示,即使我將視圖控制器的view添加到我的容器視圖中,它只是顯示一個空的白色視圖。現在使用:

let contactPickerViewController:CNContactPickerViewController = CNContactPickerViewController() 
    self.addChildViewController(contactPickerViewController) 
    contactPickerViewController.didMove(toParentViewController: self) 
    contactPickerViewController.view.frame = self.contactPickerContainerView.bounds 
    contactPickerViewController.view.translatesAutoresizingMaskIntoConstraints = true 
    contactPickerViewController.delegate = self 
    self.contactPickerContainerView.addSubview(contactPickerViewController.view) 

這兩個代碼之間唯一明顯的區別是,我沒有從視圖控制器中刪除導航欄(因爲它沒有)。除此之外,我把所有東西都放在了一起。我猜我需要更改其他一些東西才能完成這項工作,因爲將導航控制器添加到Container視圖並添加View Controller是有區別的。任何人都可以幫助我,並給我一些關於如何實現這一目標的提示?謝謝!

回答

3

使用該代碼來顯示contactPickerViewController內部的TabBar

let contactPickerViewController:CNContactPickerViewController = CNContactPickerViewController() 
contactPickerViewController.modalPresentationStyle = .overCurrentContext 
self.presentViewController(contactPicker, animated: false, completion: nil)