Search code examples
swiftwatchkitapple-watch

Is it possible to change text on another WKInterfaceController that is not currently displayed in page-based view?


I can't figure out how, from an interfaceController that is currently displayed in a page based view, to change text on another interfaceController page not currently shown.

It seems you can only change the labels of the interfaceController that is currently displayed.

Anyone know how to modify another controllers label?

var timerControllers = Array<TimerDetailController>()

class TimerDetailController: WKInterfaceController {

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)

        timerControllers.append(self)
    }


    func setLabel(){
       timerControllers[0].clientName.setText("my new label")
    }
}

I want to be able to call setLabel() from any timer page. But instead this only works if the controller displayed is the same as timerControllers[0].


Solution

  • Instead of changing a label that doesn't currently exist, you need to change the value of a data source that will be used to set the label value whenever the view is created.