objective-c - 从 Swift VC 到 Objective-C VC 的推送/执行 segue 不起作用
问题描述
我的项目是用 Swift 开发的。我们想添加一个已经在 Objective-C 中实现的特性。当我尝试从我的 Swift VC 推送到那个 Objective-C VC 时,我收到了以下警告并且推送不成功。
我确认桥接头和其他构建设置已完美配置。
我有 2 个 ObjC VC 文件。一个 VC 是完全用代码设计的,所以推送到那个 VC 没有问题。但是,在其他设计中,我无法从我的 Swift VC 推送/显示。
使用导航推送:
let story = UIStoryboard(name: "Main", bundle: nil)
let vc = story.instantiateViewController(withIdentifier: "XXXViewController") as? XXXViewController // vc always returns nil
if let vc = vc {
navigationController?.pushViewController(vc, animated: true) // can't compile because of vc is nil
}
警告:
Interface Builder 文件中的未知类 _TtC12ProjectName36XXXViewController。
使用转场:
self.performSegue(withIdentifier: "HomeToXXXVc", sender: self)
错误:
Interface Builder 文件中的未知类 _TtC12ProjectName36XXXViewController。
*** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[< UIViewController 0x10132ef60 > setValue:forUndefinedKey:]:此类与键 yyyLabel 的键值编码不兼容。
// yyyLabel - Objective-C Vc 的出口之一。
解决方案
我看到您的问题基本上出在界面构建器上。
如果错误是“*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: This class is not key value coding-compliant for key yyyLabel.” 然后它是您在 xib/storyboard 上删除的代码上的源“yyyLabel”,但您可以在课堂上访问它。
再次检查您在 xib/storyboard 中的课程,检查网点没有任何警告。
推荐阅读
- javascript - 如何检测推送菜单外的点击并关闭菜单
- batch-file - 如何批量传输重命名?
- azure - 无法在 Azure 中启用“Microsoft.Container Service”
- python - __name__ vs __package__ 在 python
- salesforce - 从 Salesforce 查询 Snowflake 表
- c++ - 我想通过 lldb 打印张量值
- r - 如何获得变量名称长度有限的数据框结构?
- mysql - MySQL 从子查询中获得前 16 名的平均值
- database - TimeoutError QueuePool limit of size x overflow xy reached, connection timed out, timeout 30
- django - Django在每个用户的UI中隐藏帖子(对象)而不影响主模型