Reputation: 2575
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()
Upvotes: 2
Views: 699
Reputation: 1800
I had the same problem and for me it was because I named IBOutlet for my WKInterfaceLabel title
which is as it turns out also a name of a method in NSObject.
Upvotes: 4
Reputation: 2575
I figured it out! It seems like there is an attribute in the view of both WKInterfaceTable and WKInterfaceLabel called "38mm Installed". The problem was, I was running the simulator on 42mm but I only had 38mm checked.
Once I checked both attributes, everything worked as planned!
Here's a screenshot of what I'm referring to:
Upvotes: 6