Reputation: 981
I'm trying to create a page based WatchKit app. When the app loads I want a page with an image and a button in a paginated view and swiping should switch between an array of images.
I tried WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"])
where home
is the identifier of the InterfaceController. I'm calling this method from another InterfaceController which is the initial interface controller. I get the page based views but the initial view is blank.
import WatchKit
import Foundation
class InterfaceController: WKInterfaceController {
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
WKInterfaceController.reloadRootControllersWithNames(["home", "home", "home", "home", "home"], contexts: ["1", "2", "3", "4", "5"])
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
reloadRootControllersWithNames
method to create a page based application?
AppDelegate
for WatchKit other than the arrow in the storyboard?Upvotes: 2
Views: 2167
Reputation: 5939
The answers to #2 and #3 are easy: you can't, at least not in the current version of WatchKit.
Upvotes: 0
Reputation: 905
Answering question 1 only:
I created a page-based app using almost exactly the technique you used here, except that I called WKInterfaceController.reloadRootControllersWithNames() from the willActivate() function, not the awakeWithContext() function. Not sure if this is important.
I am assuming that "home" is the identifier for a different WKInterfaceController? I do not think it will work correctly if you try to use the starting interface controller as the paged interface controller. So that could be the source of your problem.
However this method of specifying pages programmatically is only needed if you have a variable number of pages. If you know your page layout at build time, you can lay them all out in your storyboard, then Control-drag from one too the other, choosing the "Next page" relationship.
If you do it using the storyboard, you can have the starting interface controller as the first of the pages, and then subsequent interface controllers can use the same class if you want them to.
Upvotes: 3