将右tableview控制器更改为具有tableViewController根的导航控制器。导航控制器得到一个标识符:“导航”。
现在您可以更改doButton函数的第一个代码,并保留其余的代码。
@IBAction func doButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "navigation") as! UINavigationController
vc.preferredContentSize = CGSize(width: 260,height: 300)
vc.modalPresentationStyle = .popover
vc.view.backgroundColor = UIColor.green
if let pres = vc.presentationController {
pres.delegate = (self as UIAdaptivePresentationControllerDelegate)
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
pop.backgroundColor = vc.view.backgroundColor
}
}
最后,你会得到导航栏在你的popover。