I've seen a bunch of threads reporting this error, however, after trying all solutions, I still have the same problem. Running with the debugger I can see that the .setNumberOfRows method works, as it assigns the appropriate number of rows to my table.
import WatchKit
import Foundation
class CountInterfaceController: WKInterfaceController {
//MARK: Properties
@IBOutlet var dataTable: WKInterfaceTable!
var counters = [Counter]()
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
if let savedCounters = loadCounters(){
counters+=savedCounters
}else{
loadSampleCounters()
}
dataTable.setNumberOfRows(counters.count, withRowType: "CountRowController")
for(index, counter) in counters.enumerated(){
let row = dataTable.rowController(at: index) as! CountRowController
row.countNameLabel.setText(counter.name)
row.countCounterLabel.setText("\(counter.count)")
}
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
private func loadSampleCounters(){
guard let counter1 = Counter(name:"Pots of coffee", count: 20) else {
fatalError("Unable to instantiate counter 1")
}
guard let counter2 = Counter(name:"Tea kettles", count: 5) else {
fatalError("Unable to instantiate counter 2")
}
counters += [counter1, counter2]
}
I have created a Table Row Class and added it in the Identity field of the Table Row Controller as you can see in the picture below. The class contains the outlets for the two labels in the table row.
Table Row Controller with class
I have tried populating my table with random data from a simple array of strings but that doesn't work either(same error). I honestly don't see what I'm missing here... The only thing that I can think of is that something's changed in Swift 4 as most of the answers and info that I've found were related to Swift 3.