笔尖加载失败提出自己的视图控制器
问题描述:
当我在从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)
}
我有这个在我的iOS项目的一个工作更新到Xcode 8
和Swift 3
语言,但现在当我运行应用程序时,遇到vc.present(customDialog, animated: true, completion: nil)
行时出现崩溃。我在日志控制台得到这个消息:
终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“无法加载NIB捆绑:‘一个NSBundle /MyApp.app>(装载)’名为‘CustomDialogViewController’ “
我不明白它正在发生,因为let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle)
线不会崩溃,似乎我收到了CustomDialogViewController
对象。
有人可以帮我解决这个问题吗?谢谢
答
看起来在这种情况下,此错误是因为某些原因xib
文件缺少适当的目标成员资格。
感谢您的回答
答
当您重命名XCode以外的文件时,可能会发生此错误。要解决它,你可以从你的项目中删除文件(右键单击 - 删除和“删除参考”)。
然后,您可以重新导入项目中的文件,一切都会好的。
您确定__customDialog__被实例化吗? – Adeel
您已经在标签中指明了“Xcode 8&swift 3”,无需在标题中添加它。 –