弹出视图为空白

Popover View is Blank

我正在尝试使用代码向我的控制器添加弹出窗口。不知为何出现了popover,但是里面没有内容

我用于转换的代码是:

@IBAction func presentPopover(_ sender: UIButton) {
    //performSegueWithIdentifier("Popover", sender: self)
    let vc = PopoverViewController()
    vc.modalPresentationStyle = .popover
    let popover = vc.popoverPresentationController!
    popover.delegate = self
    popover.permittedArrowDirections = .right
    vc.popoverPresentationController?.sourceView = sender
    vc.popoverPresentationController?.sourceRect = sender.bounds
    ...
    present(vc, animated: true, completion: nil)
}

弹出视图是在情节提要中制作的,属于 class PopoverViewController 在做了一些测试后它说 PopoverViewController's viewDidAppear 被触发了。

as rmaddy 提到 let vc = PopoverViewController() 行没有使用故事板。所以你需要那样做

if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopoverViewController") as? PopoverViewController {
    vc.modalPresentationStyle = .popover
    let popover = vc.popoverPresentationController!
    popover.delegate = self
    popover.permittedArrowDirections = .right
    vc.popoverPresentationController?.sourceView = sender
    vc.popoverPresentationController?.sourceRect = sender.bounds                        
    self.present(vc, animated: true, completion: nil)
}