2016-10-22 143 views
-1

當我在從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 8Swift 3語言,但現在當我運行應用程序時,遇到vc.present(customDialog, animated: true, completion: nil)行時出現崩潰。我在日誌控制檯得到這個消息:

終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「無法加載NIB捆綁:‘一個NSBundle /MyApp.app>(裝載)’名爲‘CustomDialogViewController’ 「

我不明白它正在發生,因爲let customDialog = CustomDialogViewController(nibName: "CustomDialogViewController", bundle: bundle)線不會崩潰,似乎我收到了CustomDialogViewController對象。

有人可以幫我解決這個問題嗎?謝謝

+0

您確定__customDialog__被實例化嗎? – Adeel

+0

您已經在標籤中指明瞭「Xcode 8&swift 3」,無需在標題中添加它。 –

回答

0

看起來在這種情況下,此錯誤是因爲某些原因xib文件缺少適當的目標成員資格。

感謝您的回答

0

當您重命名XCode以外的文件時,可能會發生此錯誤。要解決它,你可以從你的項目中刪除文件(右鍵單擊 - 刪除和「刪除參考」)。

然後,您可以重新導入項目中的文件,一切都會好的。