Hello. I am working on our first steps regarding an app for the Apple Watch. We're using the WatchKit for watchOS 1 right now, since the 2.0 version seems to be still in preview.
My question is; how do I enable paged views? In the Storyboard I added a segue "nextpage" to all views, but this doesn't do anything at runtime. (Source: http://natashatherobot.com/watchkit-page-based-navigation/ )
The documentation ( https://developer.xamarin.com/guides/ios/watch/working-with/navigation/ ) states to use the following code:
var controllerNames = new [] { "pageController", "pageController", "pageController", "pageController", "pageController" }; var contexts = new [] { "First", "Second", "Third", "Fourth", "Fifth" }; ReloadRootControllers (controllerNames, contexts);
But not only does the code not compile (contexts is the wrong type for the argument expected), but it also doesn't explain what those parameters mean or what else to do.
Has anyone a working example I can look into? Thanks in advance.
Hey @VincentJunemann the contexts
are the data being used for the 'page'. Note that in the line above (the controllerNames
) the sample uses the same controller for every swipe, and the text in the context
is displayed on each page.
The associated code for that sample is in the WatchKitCatalog - for example the Awake
method for the pageController
is shown below (it is passed the context
, which is added to the dispay):
public override void Awake (NSObject context) { pageLabel.SetText (string.Format ("{0} Page", context)); }
Finally, note that ReloadRootControllers
is for when this navigation is the 'root' (ie. the first screen in your app). If you want to show this collection of pages from a button or other user action, use PresentController
(shown at the end of the doc).
As for why it's not compiling - not sure - the sample used to work. Will have to find some time to check into that.
Answers
I know AppleWatch is not as popular as some thought it would be.... but I'm sure somebody encountered this before
Hey @VincentJunemann the
contexts
are the data being used for the 'page'. Note that in the line above (thecontrollerNames
) the sample uses the same controller for every swipe, and the text in thecontext
is displayed on each page.The associated code for that sample is in the WatchKitCatalog - for example the
Awake
method for thepageController
is shown below (it is passed thecontext
, which is added to the dispay):Finally, note that
ReloadRootControllers
is for when this navigation is the 'root' (ie. the first screen in your app). If you want to show this collection of pages from a button or other user action, usePresentController
(shown at the end of the doc).As for why it's not compiling - not sure - the sample used to work. Will have to find some time to check into that.
So here is the problem; ReloadRootControllers expect an array of NSObject whereas PresentController expects an array of strings. Not a huge problem, but the inconsistency with PreentController threw me off.
Besides that, I also noticed that when I change the Storyboard on the WatchKit Extension Project, the changes won't carry over to the simulator unless I delete the app first. Otherwise it will just use the old storyboard it already had on there (resulting in unexpected behaviour when trying to use PresentController or ReloadRootControllers).
Anyway. I got it working now, so thanks for the help
@VincentJunemann How did you solve the problem? converting string [] to NSObject [] ?
ReloadRootControllers (controllerNames, contexts); ==> it must get NSObject[] related to the guide below;
https://developer.xamarin.com/guides/ios/watch/working-with/navigation/
Ok I got it,
But I would like to pass the user to second page programmatically which can equal to swipe left-to-right. Is there any way to do that? PresentController opens modally.