我该如何修复无法转换类型'UINavigationController'的值[重复]

问题描述 投票:0回答:1

这个问题与以下内容完全相同:

无法转换类型'UINavigationController'(0x37aa0dc8)t的值

我想调用我的DetailViewController的方法。但是他们崩溃并显示上面提到的错误

func move()
{
     let VC = storyboard!.instantiateViewController(withIdentifier: "PDF") as! PDFViewController

    self.navigationController?.pushViewController(VC, animated: true)
}
ios swift xcode
1个回答
1
投票

将视图控制器转换为导航控制器,并访问其topViewController属性。

let pdfVC = (storyboard!.instantiateViewController(withIdentifier: "PDF") as! UINavigationController).topViewController as! PDFViewController

self.navigationController?.pushViewController(pdfVC, animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.