I'm facing a little issue with WatchKit.
I'm trying to push a controller from a custom table row (extending NSObject); the problem is, the pushController method (which allows to navigate to a new page) can be used only in an instance of the WKinterfaceController class, but I want to do it from my custom row (so an instance of NSObject).
The Custom Table Row's code looks like:
import Foundation
import WatchKit
class CustomRowController : NSObject {
@IBOutlet weak var label: WKInterfaceLabel!
@IBAction func onButtonTapped() {
// Push action should go here
}
}
EDIT:
I ended up using this workaround instead:
let items = [0, 1]
tableView.setNumberOfRows(items.count, withRowType: "row_type")
for index in items {
let row = tableView.rowController(at: index) as! CustomRowController
row.parent = self
}
Then edited my CustomRowController so i can navigate using the parent WKInterfaceController instance like:
import Foundation
import WatchKit
class CustomRowController : NSObject {
var parent: WKInterfaceController?
@IBOutlet weak var label: WKInterfaceLabel!
@IBAction func onButtonTapped() {
// Push action should go here
parent?.pushController(withName: "name", context: nil)
}
}
It's working but, is there a better way to do this?