Getting error while loading data into WKInterfaceTable

I am creating a watchKit app / extension of my app. I am using this function to load data into WKInterfaceTable

:

// Load table into the data
func loadTableData() {

    let sharedDefault = NSUserDefaults(suiteName: "group.com.Devpr.App")
    let numberItems = sharedDefault?.objectForKey("numberItems") as? Int

    tableView.setNumberOfRows(numberItems!, withRowType: "Cell")

    var i = 0

    let task = sharedDefault?.objectForKey("\(i)WK") as? String
    let row = tableView.rowControllerAtIndex(i) as! TableRowObject  // Get a single row object for the current item
    row.lblTblRowItem.setText(task) // Set the row text to the corresponding item
    i++ // Move onto the next item
}

      

Application fails on this line functions let row = tableView.rowControllerAtIndex(i) as! TableRowObject

with this error: fatal error: unexpectedly found nil while unwrapping an Optional value

. I really can't find anything that is nil

.

Image after crash: enter image description here

I hope that some of you will help me with this. Many thanks for the help!

+3


source to share


1 answer


If numberOfItems is 0, tableView.rowControllerAtIndex (i) can be nil.



0


source







All Articles