簡體   English   中英

Swift tableview numberOfRowsInSection返回nil致命錯誤可選值

[英]Swift tableview numberOfRowsInSection return nil fatal error Optional value

您好,當表編號OFRowsInSection 0出現致命錯誤時,我有tableview並正在加載項目:展開一個Optional值時意外地找到nil

我的代碼在這里

var itemsList = [String]()


internal func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
      self.itemsmessage.text = "Listed your last \(itemsList.count) items"

    return itemsList.count
}

產生錯誤

致命錯誤:解開Optional值時意外發現nil

當返回nil時,在self.itemsmessage.text行中給出此錯誤。 謝謝。

您的self.itemsmessage可能未連接到視圖控制器中的實際控件。 檢查其是否連接。 要解決此問題,請嘗試使用安全的代碼。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM