Pavel Zagorskyy
Pavel Zagorskyy

Reputation: 135

change initial interface controller in watchKit

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?

Upvotes: 6

Views: 3373

Answers (2)

Abhayam
Abhayam

Reputation: 377

let rootControllerIdentifier = "FirstInputInterfaceController"

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

Swift 4:

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

Upvotes: 8

Pavel Zagorskyy
Pavel Zagorskyy

Reputation: 135

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

Upvotes: 1

Related Questions