Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 显示视图控制器时Nib加载失败_Ios_Swift3_Xib_Xcode8_Awakefromnib - Fatal编程技术网

Ios 显示视图控制器时Nib加载失败

Ios 显示视图控制器时Nib加载失败,ios,swift3,xib,xcode8,awakefromnib,Ios,Swift3,Xib,Xcode8,Awakefromnib,我在继承自NSObject的类中拥有此函数: open func showCustomDialogInView(vc: UIViewController) { let bundle = Bundle(for: CustomDialogViewController.self) let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle)

我在继承自
NSObject
的类中拥有此函数:

open func showCustomDialogInView(vc: UIViewController) {
    let bundle = Bundle(for: CustomDialogViewController.self)
    let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle)
    customDialog.delegate = vc
    customDialog.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
    vc.present(customDialog, animated: true, completion: nil)
}
在升级到
Xcode 8
Swift 3
语言之前,我曾在一个iOS项目中使用过这一功能,但现在当我运行应用程序时,当达到
vc.present(customDialog,动画:true,完成:nil)
行时出现崩溃。我在日志控制台中收到以下消息:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法加载捆绑包中的NIB:”NSBundle/MyApp.app>(已加载)”,名称为“CustomDialogViewController”

我不明白发生了什么,因为
让customDialog=CustomDialogViewController(nibName:“CustomDialogViewController”,bundle:bundle)
行没有崩溃,似乎我得到了一个
CustomDialogViewController
对象


有人能帮我解决这个问题吗?谢谢

当您在XCode之外重命名文件时,可能会发生此错误。要解决此问题,您只需从项目中删除文件(右键单击-删除并“删除引用”)


然后,您可以重新导入项目中的文件,一切都会正常。

在本例中,此错误似乎是由于某种原因,
xib
文件缺少适当的目标成员身份

感谢您的回答

您确定customDialog已经实例化了吗?您已经在标签中注明了“Xcode 8&swift 3”,不需要在标题中也注明。