将数据加载到WKInterfaceTable

时间:2015-05-28 18:49:25

标签: swift xcode6 watchkit

我创建了一个应用程序的watchKit app / extension。我使用此函数将数据加载到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
}

应用程序崩溃在函数的这一行:let row = tableView.rowControllerAtIndex(i) as! TableRowObject,但出现此错误:fatal error: unexpectedly found nil while unwrapping an Optional value。我真的找不到任何nil

崩溃后的图片: enter image description here

我希望你们中的某个人可以帮助我解决这个问题。非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

如果numberOfItems为0,则tableView.rowControllerAtIndex(i)可以为nil。

相关问题