WatchKit: How to do paged navigation

VincentJunemannVincentJunemann NLUniversity
edited November 2015 in Xamarin.iOS

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.

Tagged:

Best Answer

Answers

  • VincentJunemannVincentJunemann NLUniversity

    I know AppleWatch is not as popular as some thought it would be.... but I'm sure somebody encountered this before :tongue:

  • VincentJunemannVincentJunemann NLUniversity

    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

  • OnurHazarOnurHazar USUniversity ✭✭✭

    @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/

  • OnurHazarOnurHazar USUniversity ✭✭✭
    edited March 2016

    Ok I got it,

    var controllerNames = new [] { "FirstController", "SecondController"};
    var contexts = new [] { "First", "Second" };
    var contextsObj = new NSObject[contexts.Length];
    
    for (int i = 0; i < contexts.Length; i++) {
        contextsObj[i] = NSObject.FromObject(contexts[i]);
    }
    
    ReloadRootControllers (controllerNames, contextsObj);
    

    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.

Sign In or Register to comment.