2016-03-05 52 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

相关问题