Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iPhone popover上的导航栏_Ios_Swift_Uinavigationbar_Popover - Fatal编程技术网

Ios iPhone popover上的导航栏

Ios iPhone popover上的导航栏,ios,swift,uinavigationbar,popover,Ios,Swift,Uinavigationbar,Popover,我对生活没有太多要求,但我想知道如何在这款popover上获得导航栏: 这是我的故事板: 下面是我展示popover的代码: @IBAction func doButton(_ sender: Any) { let vc = PopViewController() vc.preferredContentSize = CGSize(width: 260,height: 300) vc.modalPresentationStyle = .p

我对生活没有太多要求,但我想知道如何在这款popover上获得导航栏:

这是我的故事板:

下面是我展示popover的代码:

    @IBAction func doButton(_ sender: Any) {
        let vc = PopViewController()
        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
        }
    }
}

extension ViewController : UIPopoverPresentationControllerDelegate {
    func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
        return .none
    }
}
(感谢@matt,BTW,获得上述代码!)

我在谷歌上到处搜索,还没有找到我能理解的答案。我试图在故事板中添加
导航条
,但没有骰子——唯一可以接受它的元素是
表视图中的
原型单元

请不要重定向到7年前写的东西——我已经阅读了其中的大部分,现在我正在使用Swift。当然,我可能忽略了一个明确的答案,如果是这样的话,我会感到谦虚和懊悔。但同时,如果你能得到帮助,我会非常感激的


谢谢

将右侧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中获得导航栏。

您可以尝试将
PopViewController
嵌入
UINavigationController
中,然后将导航控制器呈现给您。非常感谢,朋友!出于某种原因,我发现整个popover之旅是我在iOS中遇到的最烦人的事情。相比之下,核心数据是小菜一碟……:)