[英]Swift tableview numberOfRowsInSection return nil fatal error Optional value
Hello i have tableview and loading items when table numberOFRowsInSection 0 gives fatal error: unexpectedly found nil while unwrapping an Optional value 您好,当表编号OFRowsInSection 0出现致命错误时,我有tableview并正在加载项目:展开一个Optional值时意外地找到nil
My code here 我的代码在这里
var itemsList = [String]()
internal func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
self.itemsmessage.text = "Listed your last \(itemsList.count) items"
return itemsList.count
}
Giving Error 产生错误
fatal error: unexpectedly found nil while unwrapping an Optional value
致命错误:解开Optional值时意外发现nil
When return nil gives this error in self.itemsmessage.text line. 当返回nil时,在self.itemsmessage.text行中给出此错误。 Thank you.
谢谢。
Your self.itemsmessage may not be connected to the actual control in your view controller. 您的self.itemsmessage可能未连接到视图控制器中的实际控件。 Check that its connected.
检查其是否连接。 To put safe code around that try this.
要解决此问题,请尝试使用安全的代码。
if let message = self.itemsmessage { message.text = "Listed your last \\(itemsList.count) items" } else { print("Seems like your itemsmessage is not connected to a text label") }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.