首页 > 解决方案 > 从 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 的出口之一。

标签: objective-cswiftuistoryboardseguexcode-storyboardbridging-header

解决方案


我看到您的问题基本上出在界面构建器上。

如果错误是“*** 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 中的课程,检查网点没有任何警告。


推荐阅读