2016-03-05 49 views
0

我遇到了的常見錯誤致命錯誤:意外地發現零,同時展開可選值(lldb)。我已經研究過其他問題,但沒有一個回答我的問題。致命錯誤:在解包可選值(lldb)時意外地發現爲零(lldb)

的錯誤出現在下面的代碼四號線:

if content[indexPath.row].urgent == true { 
     cell.urgentLabel.text = "URGENT" 
} else { 
     cell.urgentLabel.text = "" 
} 

上的其他問題,說我應該在4號線"",但我會如何解決這個問題,它仍然顯示沒有文字。

該碼與下面的數組:

var content:[Agenda] = [ 
    Agenda(subject: "Read this article", deadline: "1-2 days", urgent: false), 
    Agenda(subject: "Respond to this email", deadline: "ASAP", urgent: true), 
    Agenda(subject: "Add this to diary", deadline: "When at home", urgent: true), 
    Agenda(subject: "Listen to this song", deadline: "When finished working", urgent: false), 
    Agenda(subject: "Check out this holiday destination", deadline: "At the weekend", urgent: false), 
    Agenda(subject: "Download this podcast", deadline: "1-4 days", urgent: false), 
    Agenda(subject: "Update notes", deadline: "When at home", urgent: true) 
] 
+0

確認emergencyLabel已正確連接。 – Moritz

+0

@ EricD.Oops!這是問題所在。把它作爲答案,我會接受它。 –

+0

完成。謝謝。 – Moritz

回答

0

由於我沒有看到這個代碼的任何強制展開自選,這個問題並非來自這個共同的問題。

不過,這是一個強制解包零的問題,所以......它可能來自一個隱式解包的可選,例如一個IBOutlet。

如果InterfaceBuilder和IBOutlet之間的連接丟失,則該對象將爲零,並且嘗試訪問對象屬性時應用程序將崩潰。

解決方法是在InterfaceBuilder中重新創建到IBOutlet /對象的鏈接,您的情況爲urgentLabel

相關問題