-1

I need to slide to next page(page2) what i need from button(page1) as attached image

could you advice me ? Thanks you.

main code

//-------------- open group page ---------------//
  WKInterfaceController.reloadRootControllers(
          withNames:["page1","page2"], contexts: ["0","0"],pageIndex:1
        )

page2 code

//-------------- start workout ----------------//
func startworkOut(){
.......
}

//--------------- stop workout ---------------//

func stopworkOut(){
.......
}

page1 code

//-------------- start stop workout --------------//
workoutStatus = false
if(!workoutStatus){
 // set value to startworkOut at page 2
workoutStatus = true
}
if(workoutStatus){
 // set value to stopworkOut at page 2
workoutStatus = false
}

1 Answers1

0

Both those controllers need to talk to each other.
There are a few ways, but I would go with a common class object.

Think of the controllers as dumb views that only show information and send interaction events (think MVVM but we're not taking that pattern now).
Let the real workout logic reside in a class object that you share between the 2 controllers.


Example:

class WorkoutManager {    
    var workoutStarted: Bool = false

    func startWorkout() {
        workoutStarted = true
        //...
    }

    func stopWorkout() {
        workoutStarted = false
        //...
    }    
}

Open Group related code:

//Common object to be sent to both controllers
let manager = WorkoutManager()

WKInterfaceController.reloadRootControllers(withNamesAndContexts: 
    [(name: "page1", context: manager as AnyObject),
     (name: "page2", context: manager as AnyObject)])

In Both Controllers (Very Important):

var manager: WorkoutManager!

override func awake(withContext context: Any?) {
    //...
    self.manager = context as! WorkoutManager
    //...
}

Page 1 related code:

if(manager.workoutStarted == false) {
    manager.startWorkout()
}
else {
    manager.stopWorkout()
}

Page 2 related code:

func startworkOut() {
    manager.startWorkout()
}

func stopworkOut() {
    manager.stopWorkout()
}

This WorkoutManager is just an idea on how to proceed. It should surely contain other content that you want to show, like the heart rate and distance.
Best of luck

staticVoidMan
  • 19,275
  • 6
  • 69
  • 98