从显示为弹出窗口的其他 viewcontroller 推送到 ViewController - 没有故事板

PUSH to ViewController from other viewcontroller which is presented as popover - WITHOUT STORY BOARD

我没有在我的项目中使用 StoryBoard。我已经将一个视图控制器呈现为 popOver 样式。

let vcOne                               = ViewControllerOne()
    vcOne.showCorrectionFactor          = true
    vcOne.modalPresentationStyle        = .popover
    let pop                             = vcOne.popoverPresentationController
    pop?.sourceView                     = self.view
    pop?.sourceRect                     = sender.frame
    vcOne.preferredContentSize          = CGSize(width: 400, height: 500)
    self.present(vcOne, animated: true, completion: nil)

现在我想从 ViewControllerOne() 导航到其他视图控制器并在此弹出窗口中。

我是这样做的

let vc = PairViewController()
self.navigationController?.pushViewController(vc, animated: true)

但是 self.navigationController? 得到的是零值。没有故事板我怎么能实现这个。

你没有在UINavigationController中嵌入ViewControllerOne,所以self.navigationController当然是nil

只需这样做:

// embed it!
let navController                   = UINavigationController(rootViewController: vcOne)
// get the popover presentation controller from the navigation controller!
let pop                             = navController.popoverPresentationController
pop?.sourceView                     = self.view
pop?.sourceRect                     = sender.frame
vcOne.preferredContentSize          = CGSize(width: 400, height: 500)
// present navController rather than vcOne!
self.present(navController, animated: true, completion: nil)