ios - 我该如何解决 Could not cast value of type 'UINavigationController'

标签 ios swift xcode

<分区>

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

我想调用我的 DetailViewController 的方法。但它们崩溃并显示上述错误

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

    self.navigationController?.pushViewController(VC, animated: true)
}

最佳答案

将 View Controller 转换为导航 Controller ,并访问其 topViewController 属性。

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

self.navigationController?.pushViewController(pdfVC, animated: true)

关于ios - 我该如何解决 Could not cast value of type 'UINavigationController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48030015/

相关文章:

objective-c - CGContext 的静态背景

ios - 当滚动出 View 时,覆盖的 setSelected 和 setHighlighted 不保留选定的背景

xcode - 获取 UITableView 滚动到选定的 UITextField 并避免被键盘隐藏

ios - 更新到 Xcode 8 后编译项目时出现问题

ios - 当 View Controller 被关闭时,补充 View 会短暂保留

ios - Google Play 游戏服务 iOS : [UITableViewWrapperView style]: unrecognized selector sent to instance

ios - 如何在Swift中自行搭建UISlider自动滑动?

ios - 如何为客户端应用程序创建配置文件?

ios - 将 Kal 添加为 subview 时出现奇怪的空间问题

ios - Alamofire异步请求在for循环中乱序发生