1

The title sums it up. I've tried disconnecting/reconnecting all the IBOutlets. Here's the code on my InterfaceController where I set up the WKInterfaceTable:

func setupLoadingTable () {
    self.myTable.setNumberOfRows(1, withRowType:"universalRowID")

    for (var i = 0; i<self.myTable.numberOfRows; i++){
        var row = self.myTable.rowControllerAtIndex(i) as! UniversalRowView
        row.mainTitle.setText("Hello world") //THIS THROWS AN ERROR
    }
}

Here's the code for my UniversalRowView which is my custom row class:

import WatchKit

class UniversalRowView: NSObject {

    @IBOutlet weak var mainTitle: WKInterfaceLabel!
    @IBOutlet weak var subTitle: WKInterfaceLabel!

}

The IBOutlets for the Table is properly connected. The row on Storyboard is set to type UniversalRowView and outlets for both labels are properly connected.

The line:

row.mainTitle.setText("Hello world")

throws the following error: "fatal error: unexpectedly found nil while unwrapping an Optional value"

Also, when I comment that code out, I don't see the stock WKInterfaceLabels on the simulator as they appear on the Storyboard. I feel like this is an error as well but I don't know what to make of it.

Edit: Calling setupLoadingTable() in willActivate()

4

2 回答 2

6

我想到了!似乎在 WKInterfaceTable 和 WKInterfaceLabel 的视图中都有一个名为“38mm Installed”的属性。问题是,我在 42mm 上运行模拟器,但我只检查了 38mm

一旦我检查了这两个属性,一切都按计划进行!

这是我所指的屏幕截图:

在此处输入图像描述

于 2015-07-03T07:06:14.953 回答
3

我遇到了同样的问题,对我来说,这是因为我为我的 WKInterfaceLabel 命名了 IBOutlet,title事实证明这也是 NSObject 中方法的名称。

于 2017-04-17T11:58:30.027 回答