change initial interface controller in watchKit

3.3k views Asked by At

I have two interface controllers, controller1.swift and controller2.swift

These are connected with push-segue (after button action). But in some cases I need to skip controller1 and show just controller2. In iOS app I do this in appDelegate, setting rootViewcontroller, etc. What is the way to do this in Apple Watch Extension?

any guides or help?

2

There are 2 answers

0
Pavel Zagorskyy On

After long research work I found only one solution - create some SplashController, with some splash screen, and in

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

track something that you need, after track present some controllers, example

    if !isCounting {
        self.presentControllerWithName("Interface", context: nil)
    } else {
        self.presentControllerWithName("Timer", context: nil)
    }

hope it will help someone. P.S. isCounting is stored in NSUserDefaults

0
Abhayam On
let rootControllerIdentifier = "FirstInputInterfaceController"

WKInterfaceController.reloadRootControllers(withNames: [rootControllerIdentifier], contexts: nil)

Swift 4:

let rootControllerIdentifier = "FirstInputInterfaceController"
WKInterfaceController.reloadRootControllers(withNamesAndContexts: [(name: rootControllerIdentifier, context: [:] as AnyObject)])