2016-11-21 106 views
0

如果我是正確的:EXC_BAD_INSTRUCTION意味着應用程序崩潰,因爲某些東西不存在。但是我得到的錯誤Swift Firebase。線程1:EXC_BAD_INSTRUCTION(代碼= EXC_I386_INVOP,子代碼= 0x0)

(Google上搜尋它,並試圖讓我的頭一輪之後):

Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

當我試圖和加載另一個視圖。

這就是應用程序崩潰的功能:

func loginUserNeedsEmailVerification() { 

    let next = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController 
    next.isUserLoggedInButNeedsEmail = true 
    self.present(next, animated: true, completion: nil) 
} 

我調用這個函數。從另外一個功能,像這樣:

perform(#selector(loginUserNeedsEmailVerification), with: nil, afterDelay: 0) 

即使該文件存在,我改變了像這樣:

let next = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController 
    next?.isUserLoggedInButNeedsEmail = true 
    self.present(next?, animated: true, completion: nil) 

然後另一個錯誤在最後一行拋出:

Value of optional type is not unwrapped.

當我點擊小修復它。它改變了代碼這樣:

self.present((next?)!, animated: true, completion: nil) 

但隨後,類似的錯誤也是如此:

optional chain has no effect

我在做什麼錯誤,以及如何解決這個問題?

+0

你是否在任何類中聲明瞭帶有數據庫引用的全局變量? – Dravidian

+0

@Dravidian我不確定與呈現視圖控制器有什麼關係?是的,我有標準的FIRDatabase.database()。reference() – JamesG

+0

@JamesG這次崩潰與Firebase無關。檢查'storyboard'屬性是否爲'nil'或'instantiateViewController'方法返回的'UIViewController'實例爲'nil' –

回答

0

我只是在instantiateViewController, 期間遇到同樣的問題,但它有點不同,因爲我從另一個類調用該方法。

一種常見方式,看看有什麼不順心是storyboard 這樣經過設置?!self.storyboard!.instantiateViewController

你可能會看到這個錯誤
fatal error: unexpectedly found nil while unwrapping an Optional value
這意味着故事板被發現零。在我的情況下,我以某種方式無法獲得UIStoryboard的現有參考(因爲我從另一個類中調用)。

我找到解決的辦法是首先重新申報UIStoryboard:
let next = UIStoryboard(name: "Main", bundle:nil).instantiateViewController(withIdentifier: "LoginViewController") as? LoginViewController
我不知道爲什麼這樣的工作,因爲它仍然沒有得到故事板的電流基準,但它爲我工作。

相關問題