简体   繁体   中英

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

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

When return nil gives this error in self.itemsmessage.text line. Thank you.

Your self.itemsmessage may not be connected to the actual control in your view controller. 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") }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM