简体   繁体   English

不能在`storyboard.instantiateViewController`之后下调

[英]Can't downcast after `storyboard.instantiateViewController`

I'm using storyboard.instantiateViewController to start a TableViewController, but when I try to downcast it, I get an error: 我正在使用storyboard.instantiateViewController启动TableViewController,但是当我尝试向下转换时,出现错误:

Could not cast value of type 'UITableViewController' (0x109b30de8) to 'PresenceTableViewController' (0x1060329f0).

My class PresenceTableViewController is a subclass of UITableViewController, and the storyboard has assigned the VC class correctly. 我的PresenceTableViewController类是UITableViewController的子类,并且情节提要正确分配了VC类。 在此处输入图片说明

So why would this fail? 那为什么会失败呢?

presenceViewController = storyboard.instantiateViewController(withIdentifier: "userPresenceTable") as! PresenceTableViewController

I tried the possible cases for "Could not cast value..." and it was woking fine for all cases, and then I generated this error in one case when module was not inherited from target. 我尝试了“无法转换值...”的可能情况,并且在所有情况下都可以正常工作,然后在某个情况下,当模块未从目标继承时,我就产生了此错误。 This solved the problem for me. 这为我解决了问题。

Just re-enter the class type on storyboard, it will automatically select "Inherit module from target". 只需在情节提要上重新输入类类型,它将自动选择“从目标继承模块”。 This would solve your problem. 这样可以解决您的问题。

在此处输入图片说明

Also make sure that your controller from you want to use must be embed with navigation bar 还要确保您要使用的控制器必须嵌入导航栏

 let tableviewController = self.storyboard?.instantiateViewController(withIdentifier: "tableviewController") as! tableviewController
 self.navigationController?.pushViewController(tableviewController, animated: true)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift:线程 1:在 storyBoard.instantiateViewController 之后发出 SIGABRT 信号 - Swift: Thread 1: signal SIGABRT after storyBoard.instantiateViewController StoryBoard.InstantiateViewController提供“ Interface Builder文件中的未知类testController” - StoryBoard.InstantiateViewController giving “Unknown class testController in Interface Builder file” Swift iOS -storyboard.instantiateViewController(withIdentifier :)导致保留周期 - Swift iOS -storyboard.instantiateViewController(withIdentifier:) causing retain cycle Storyboard?.instantiateViewController(withIdentifier:“”)为! 视图控制器 - storyboard?.instantiateViewController(withIdentifier: “ ”) as! viewcontroller 在InstantiateViewController()调用中视图未从Storyboard加载 - View not loading from Storyboard on InstantiateViewController() call 在 self.storyboard?.instantiateViewController 为什么 self.storyboard 是可选的? - In self.storyboard?.instantiateViewController why self.storyboard is optional? 单击按钮后尝试实例化ViewController时出现错误 - Errors when try to InstantiateViewController after button click 构建后无法在Xcode Simulator故事板上看到TextView - Can't See TextView in Xcode Simulator Storyboard after building 我不能将NSDictionary,CFDictionaryRef或NSMutableDictionary转换为SecItemAdd() - I can't downcast an NSDictionary, CFDictionaryRef, nor an NSMutableDictionary, to SecItemAdd() 为什么在Swift中实例化ViewController(withIdentifier :)之后需要向下转换 - Why is downcasting required after instantiateViewController(withIdentifier:) in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM