首页 > 解决方案 > 推送没有情节提要的 ViewController

问题描述

我尝试像这样(Swift 4)从主 ViewController 推送视图控制器:

@objc func childAction(sender: UIButton!) {
    print("Child button tapped")
    let vc = childDetailViewController()
    self.navigationController?.pushViewController(vc, animated: true)
}

文本被打印,但 viewController 没有被推送。我错过了什么?

标签: swiftxcodeswift4

解决方案


可能self.navigationControllernil

尝试呈现它:self.present(vc, animated: true)

UPD

此外,如果它没有帮助,请尝试临时更改您的childDetailViewControllerto UIViewController(),看看会发生什么。如果您在点击后看到空白屏幕,则问题出在 childDetailViewController


推荐阅读