WKInterfaceTable & setNumberOfRows getting "unexpectedly found zero while expanding optional value" failure
I am working with WatchKit, I have a simple interface with only a table, but I am getting an error with only a few lines of code, maybe I forgot something really basic.
My interface:
the row inside the table has an id:
and a custom class:
The controller is implemented with this code:
import WatchKit
import Foundation
class ActiveListController: WKInterfaceController
{
@IBOutlet weak var tableView: WKInterfaceTable!
override func awakeWithContext(context: AnyObject?)
{
super.awakeWithContext(context)
loadData()
}
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()
}
func loadData()
{
tableView.setNumberOfRows(10, withRowType: "ItemRow") // GET ERROR
for index in 0...9
{
let row = tableView.rowControllerAtIndex(index) as! ItemRow
row.nameLabel.setText("test")
}
}
}
and obviously I have my own custom class for one line
import Foundation
import WatchKit
class ItemRow : NSObject
{
@IBOutlet weak var checkImage: WKInterfaceImage!
@IBOutlet weak var nameLabel: WKInterfaceLabel!
}
So when I run the application, I get an error when I try to set the number of lines, but I really can't figure out what nil is:
fatal error: unexpectedly found nil while expanding an optional value
Maybe this is a simple error, maybe not, but please help me: \
source to share
finally i found my mistake.
I forgot to set only one interface for the Apple Watch as the initial controller.
Yes, unbelievable and embarrassing, but true. The bug that Xcode provides is not the best, it would be better something like "initial controller missing".
Hope my question and answer can help someone one day :)
source to share