Page Based “reloadRootControllersWithNames:” on launch loop?












9















- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[WKInterfaceController reloadRootControllersWithNames:@[@"pageOne", @"pageTwo"] contexts:nil];
}


Following Apple's guidelines




Call this method to reload the pages in your app’s page-based interface. At launch time, you use this method to customize the set of pages you want displayed.




at launch time, only results in a loop. With each reload calling awakeWithContext or will Activate or init again and again.



Is there a better way to go about reloading the Page-Based app on launch with a loop occurring?










share|improve this question























  • awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

    – Javier Flores Font
    Mar 10 '15 at 0:47











  • Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

    – devone
    Mar 10 '15 at 3:02
















9















- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[WKInterfaceController reloadRootControllersWithNames:@[@"pageOne", @"pageTwo"] contexts:nil];
}


Following Apple's guidelines




Call this method to reload the pages in your app’s page-based interface. At launch time, you use this method to customize the set of pages you want displayed.




at launch time, only results in a loop. With each reload calling awakeWithContext or will Activate or init again and again.



Is there a better way to go about reloading the Page-Based app on launch with a loop occurring?










share|improve this question























  • awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

    – Javier Flores Font
    Mar 10 '15 at 0:47











  • Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

    – devone
    Mar 10 '15 at 3:02














9












9








9


3






- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[WKInterfaceController reloadRootControllersWithNames:@[@"pageOne", @"pageTwo"] contexts:nil];
}


Following Apple's guidelines




Call this method to reload the pages in your app’s page-based interface. At launch time, you use this method to customize the set of pages you want displayed.




at launch time, only results in a loop. With each reload calling awakeWithContext or will Activate or init again and again.



Is there a better way to go about reloading the Page-Based app on launch with a loop occurring?










share|improve this question














- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[WKInterfaceController reloadRootControllersWithNames:@[@"pageOne", @"pageTwo"] contexts:nil];
}


Following Apple's guidelines




Call this method to reload the pages in your app’s page-based interface. At launch time, you use this method to customize the set of pages you want displayed.




at launch time, only results in a loop. With each reload calling awakeWithContext or will Activate or init again and again.



Is there a better way to go about reloading the Page-Based app on launch with a loop occurring?







ios watchkit apple-watch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 10 '15 at 0:08









devonedevone

19828




19828













  • awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

    – Javier Flores Font
    Mar 10 '15 at 0:47











  • Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

    – devone
    Mar 10 '15 at 3:02



















  • awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

    – Javier Flores Font
    Mar 10 '15 at 0:47











  • Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

    – devone
    Mar 10 '15 at 3:02

















awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

– Javier Flores Font
Mar 10 '15 at 0:47





awakewithcontext is called every time you call reloadRootControllersWithNames, thats why it result in a loop. Just configure your default page-base navigation in the storyboard

– Javier Flores Font
Mar 10 '15 at 0:47













Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

– devone
Mar 10 '15 at 3:02





Yes, I read Apple's docs incorrectly perceiving at launch time it was suppose to do all the work for you.

– devone
Mar 10 '15 at 3:02












4 Answers
4






active

oldest

votes


















20














This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:





  • MainInterfaceController (the main link in storyboard points here)


  • PageOneInterfaceController - your first interface to display in the page set


  • PageTwoInterfaceController - your second interface in the page set


The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.



I have used this approach in an app that had many different page sets to choose from and it worked very well.






share|improve this answer
























  • Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

    – devone
    Mar 10 '15 at 3:00











  • Glad to help dude!

    – cnoon
    Mar 10 '15 at 7:29











  • reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

    – Rohit Gupta
    Apr 5 '15 at 16:11











  • @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

    – Walter Martin Vargas-Pena
    Apr 13 '15 at 11:34



















5














That is why awakeWithContext: exists. The first time your app is launched, the initial controller is passed nil as context. But if you reloadRootControllersWithNames:contexts:, you have an opportunity to pass a custom context instance and thus distinguish the launch mode.






share|improve this answer



















  • 1





    This is a much simpler and cleaner approach, thanks!

    – Dmorneault
    Apr 11 '17 at 4:14











  • This is how I implement mine as well!

    – Pranoy C
    Dec 10 '18 at 6:25



















0














calling WKInterfaceController.reloadRootControllers causes the awake function to be called a second time. This is the solution I use - it is straight forward, compact, and eliminates the recursive loop. This example has two page based views called mainControls and nowPlaying that are configured with contexts. Note the key thing here is to configure the mainControls view controller with an empty string context then that context is checked and returns if it is being called again due to the WKInterfaceController.reloadRootControllers statement that configured the context to "". Note the first time awake runs the context for the main view controller will be nil. Also note the second context is an implementation detail specific to my implementation - this could be any object that you want to pass to the second view controller.



override func awake(withContext context: Any?) {
super.awake(withContext: context)
if let _ = context as? String {
print("already configured!")
return
}
print("configuring...")
WKInterfaceController.reloadRootControllers(withNames: ["mainControls", "nowPlaying"], contexts: ["", interaction])
}





share|improve this answer































    -2














    Really easy to solve, and does not require Multiple Page Controllers -- Just use once



    Create a class variable (not an instance variable) and use that as your flag to ensure that your call to reloadRootControllers is only ever called once.



    static NSString* hasLaunchedIfNotNullString = NULL;

    - (void)awakeWithContext:(id)context
    {
    if(hasLaunchedIfNotNullString == NULL)
    {
    //START Code which gets executed once
    hasLaunchedIfNotNullString = @"";

    ...
    [WKInterfaceController reloadRootControllersWithNames:YOUR_ARRAY contexts:CONTEXTS];
    // END code which gets executed once
    }
    }





    share|improve this answer
























    • Using a string field as a flag is generally a bad idea.

      – Aleks N.
      Jul 10 '15 at 9:30











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28954007%2fpage-based-reloadrootcontrollerswithnames-on-launch-loop%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    20














    This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:





    • MainInterfaceController (the main link in storyboard points here)


    • PageOneInterfaceController - your first interface to display in the page set


    • PageTwoInterfaceController - your second interface in the page set


    The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.



    I have used this approach in an app that had many different page sets to choose from and it worked very well.






    share|improve this answer
























    • Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

      – devone
      Mar 10 '15 at 3:00











    • Glad to help dude!

      – cnoon
      Mar 10 '15 at 7:29











    • reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

      – Rohit Gupta
      Apr 5 '15 at 16:11











    • @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

      – Walter Martin Vargas-Pena
      Apr 13 '15 at 11:34
















    20














    This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:





    • MainInterfaceController (the main link in storyboard points here)


    • PageOneInterfaceController - your first interface to display in the page set


    • PageTwoInterfaceController - your second interface in the page set


    The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.



    I have used this approach in an app that had many different page sets to choose from and it worked very well.






    share|improve this answer
























    • Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

      – devone
      Mar 10 '15 at 3:00











    • Glad to help dude!

      – cnoon
      Mar 10 '15 at 7:29











    • reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

      – Rohit Gupta
      Apr 5 '15 at 16:11











    • @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

      – Walter Martin Vargas-Pena
      Apr 13 '15 at 11:34














    20












    20








    20







    This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:





    • MainInterfaceController (the main link in storyboard points here)


    • PageOneInterfaceController - your first interface to display in the page set


    • PageTwoInterfaceController - your second interface in the page set


    The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.



    I have used this approach in an app that had many different page sets to choose from and it worked very well.






    share|improve this answer













    This is a common problem with WatchKit apps since we no longer have a UIApplicationDelegate to handle such set up. A good approach would be to structure your code as follows:





    • MainInterfaceController (the main link in storyboard points here)


    • PageOneInterfaceController - your first interface to display in the page set


    • PageTwoInterfaceController - your second interface in the page set


    The MainInterfaceController will never actually get displayed. You will always launch into a different set of interface controllers depending on the cached state of the companion iOS App in MainInterfaceController.awakeWithContent(). This way, you use the MainInterfaceController in a similar manner that we use the UIApplicationDelegate in iOS to set up the window and root view controller.



    I have used this approach in an app that had many different page sets to choose from and it worked very well.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 10 '15 at 2:38









    cnooncnoon

    14.8k34659




    14.8k34659













    • Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

      – devone
      Mar 10 '15 at 3:00











    • Glad to help dude!

      – cnoon
      Mar 10 '15 at 7:29











    • reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

      – Rohit Gupta
      Apr 5 '15 at 16:11











    • @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

      – Walter Martin Vargas-Pena
      Apr 13 '15 at 11:34



















    • Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

      – devone
      Mar 10 '15 at 3:00











    • Glad to help dude!

      – cnoon
      Mar 10 '15 at 7:29











    • reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

      – Rohit Gupta
      Apr 5 '15 at 16:11











    • @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

      – Walter Martin Vargas-Pena
      Apr 13 '15 at 11:34

















    Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

    – devone
    Mar 10 '15 at 3:00





    Wow brilliant, that's a clever workout, I was about to use a bunch of booleans and not looking forward to it. Thanks a many!

    – devone
    Mar 10 '15 at 3:00













    Glad to help dude!

    – cnoon
    Mar 10 '15 at 7:29





    Glad to help dude!

    – cnoon
    Mar 10 '15 at 7:29













    reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

    – Rohit Gupta
    Apr 5 '15 at 16:11





    reloadRootControllersWithNames - this does not call deactivate on the controllers that were already present. Any solutions if something needs to be stopped (like a timer) on the controller that was visible?

    – Rohit Gupta
    Apr 5 '15 at 16:11













    @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

    – Walter Martin Vargas-Pena
    Apr 13 '15 at 11:34





    @cnoon Ive been using this to present the correct WKInterface Controller from a remote notification. I end up calling reloadRootControllersWithNames twice once in awakeWithContext of my MainInterfaceController and once in - (void)handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)remoteNotification. However i see three dots in the page control at first which then becomes two. Any way to avoid that? Am i approaching this the correct way?

    – Walter Martin Vargas-Pena
    Apr 13 '15 at 11:34













    5














    That is why awakeWithContext: exists. The first time your app is launched, the initial controller is passed nil as context. But if you reloadRootControllersWithNames:contexts:, you have an opportunity to pass a custom context instance and thus distinguish the launch mode.






    share|improve this answer



















    • 1





      This is a much simpler and cleaner approach, thanks!

      – Dmorneault
      Apr 11 '17 at 4:14











    • This is how I implement mine as well!

      – Pranoy C
      Dec 10 '18 at 6:25
















    5














    That is why awakeWithContext: exists. The first time your app is launched, the initial controller is passed nil as context. But if you reloadRootControllersWithNames:contexts:, you have an opportunity to pass a custom context instance and thus distinguish the launch mode.






    share|improve this answer



















    • 1





      This is a much simpler and cleaner approach, thanks!

      – Dmorneault
      Apr 11 '17 at 4:14











    • This is how I implement mine as well!

      – Pranoy C
      Dec 10 '18 at 6:25














    5












    5








    5







    That is why awakeWithContext: exists. The first time your app is launched, the initial controller is passed nil as context. But if you reloadRootControllersWithNames:contexts:, you have an opportunity to pass a custom context instance and thus distinguish the launch mode.






    share|improve this answer













    That is why awakeWithContext: exists. The first time your app is launched, the initial controller is passed nil as context. But if you reloadRootControllersWithNames:contexts:, you have an opportunity to pass a custom context instance and thus distinguish the launch mode.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 10 '15 at 9:26









    Aleks N.Aleks N.

    4,69913439




    4,69913439








    • 1





      This is a much simpler and cleaner approach, thanks!

      – Dmorneault
      Apr 11 '17 at 4:14











    • This is how I implement mine as well!

      – Pranoy C
      Dec 10 '18 at 6:25














    • 1





      This is a much simpler and cleaner approach, thanks!

      – Dmorneault
      Apr 11 '17 at 4:14











    • This is how I implement mine as well!

      – Pranoy C
      Dec 10 '18 at 6:25








    1




    1





    This is a much simpler and cleaner approach, thanks!

    – Dmorneault
    Apr 11 '17 at 4:14





    This is a much simpler and cleaner approach, thanks!

    – Dmorneault
    Apr 11 '17 at 4:14













    This is how I implement mine as well!

    – Pranoy C
    Dec 10 '18 at 6:25





    This is how I implement mine as well!

    – Pranoy C
    Dec 10 '18 at 6:25











    0














    calling WKInterfaceController.reloadRootControllers causes the awake function to be called a second time. This is the solution I use - it is straight forward, compact, and eliminates the recursive loop. This example has two page based views called mainControls and nowPlaying that are configured with contexts. Note the key thing here is to configure the mainControls view controller with an empty string context then that context is checked and returns if it is being called again due to the WKInterfaceController.reloadRootControllers statement that configured the context to "". Note the first time awake runs the context for the main view controller will be nil. Also note the second context is an implementation detail specific to my implementation - this could be any object that you want to pass to the second view controller.



    override func awake(withContext context: Any?) {
    super.awake(withContext: context)
    if let _ = context as? String {
    print("already configured!")
    return
    }
    print("configuring...")
    WKInterfaceController.reloadRootControllers(withNames: ["mainControls", "nowPlaying"], contexts: ["", interaction])
    }





    share|improve this answer




























      0














      calling WKInterfaceController.reloadRootControllers causes the awake function to be called a second time. This is the solution I use - it is straight forward, compact, and eliminates the recursive loop. This example has two page based views called mainControls and nowPlaying that are configured with contexts. Note the key thing here is to configure the mainControls view controller with an empty string context then that context is checked and returns if it is being called again due to the WKInterfaceController.reloadRootControllers statement that configured the context to "". Note the first time awake runs the context for the main view controller will be nil. Also note the second context is an implementation detail specific to my implementation - this could be any object that you want to pass to the second view controller.



      override func awake(withContext context: Any?) {
      super.awake(withContext: context)
      if let _ = context as? String {
      print("already configured!")
      return
      }
      print("configuring...")
      WKInterfaceController.reloadRootControllers(withNames: ["mainControls", "nowPlaying"], contexts: ["", interaction])
      }





      share|improve this answer


























        0












        0








        0







        calling WKInterfaceController.reloadRootControllers causes the awake function to be called a second time. This is the solution I use - it is straight forward, compact, and eliminates the recursive loop. This example has two page based views called mainControls and nowPlaying that are configured with contexts. Note the key thing here is to configure the mainControls view controller with an empty string context then that context is checked and returns if it is being called again due to the WKInterfaceController.reloadRootControllers statement that configured the context to "". Note the first time awake runs the context for the main view controller will be nil. Also note the second context is an implementation detail specific to my implementation - this could be any object that you want to pass to the second view controller.



        override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        if let _ = context as? String {
        print("already configured!")
        return
        }
        print("configuring...")
        WKInterfaceController.reloadRootControllers(withNames: ["mainControls", "nowPlaying"], contexts: ["", interaction])
        }





        share|improve this answer













        calling WKInterfaceController.reloadRootControllers causes the awake function to be called a second time. This is the solution I use - it is straight forward, compact, and eliminates the recursive loop. This example has two page based views called mainControls and nowPlaying that are configured with contexts. Note the key thing here is to configure the mainControls view controller with an empty string context then that context is checked and returns if it is being called again due to the WKInterfaceController.reloadRootControllers statement that configured the context to "". Note the first time awake runs the context for the main view controller will be nil. Also note the second context is an implementation detail specific to my implementation - this could be any object that you want to pass to the second view controller.



        override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        if let _ = context as? String {
        print("already configured!")
        return
        }
        print("configuring...")
        WKInterfaceController.reloadRootControllers(withNames: ["mainControls", "nowPlaying"], contexts: ["", interaction])
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 5:51









        Richie HyattRichie Hyatt

        1,50911613




        1,50911613























            -2














            Really easy to solve, and does not require Multiple Page Controllers -- Just use once



            Create a class variable (not an instance variable) and use that as your flag to ensure that your call to reloadRootControllers is only ever called once.



            static NSString* hasLaunchedIfNotNullString = NULL;

            - (void)awakeWithContext:(id)context
            {
            if(hasLaunchedIfNotNullString == NULL)
            {
            //START Code which gets executed once
            hasLaunchedIfNotNullString = @"";

            ...
            [WKInterfaceController reloadRootControllersWithNames:YOUR_ARRAY contexts:CONTEXTS];
            // END code which gets executed once
            }
            }





            share|improve this answer
























            • Using a string field as a flag is generally a bad idea.

              – Aleks N.
              Jul 10 '15 at 9:30
















            -2














            Really easy to solve, and does not require Multiple Page Controllers -- Just use once



            Create a class variable (not an instance variable) and use that as your flag to ensure that your call to reloadRootControllers is only ever called once.



            static NSString* hasLaunchedIfNotNullString = NULL;

            - (void)awakeWithContext:(id)context
            {
            if(hasLaunchedIfNotNullString == NULL)
            {
            //START Code which gets executed once
            hasLaunchedIfNotNullString = @"";

            ...
            [WKInterfaceController reloadRootControllersWithNames:YOUR_ARRAY contexts:CONTEXTS];
            // END code which gets executed once
            }
            }





            share|improve this answer
























            • Using a string field as a flag is generally a bad idea.

              – Aleks N.
              Jul 10 '15 at 9:30














            -2












            -2








            -2







            Really easy to solve, and does not require Multiple Page Controllers -- Just use once



            Create a class variable (not an instance variable) and use that as your flag to ensure that your call to reloadRootControllers is only ever called once.



            static NSString* hasLaunchedIfNotNullString = NULL;

            - (void)awakeWithContext:(id)context
            {
            if(hasLaunchedIfNotNullString == NULL)
            {
            //START Code which gets executed once
            hasLaunchedIfNotNullString = @"";

            ...
            [WKInterfaceController reloadRootControllersWithNames:YOUR_ARRAY contexts:CONTEXTS];
            // END code which gets executed once
            }
            }





            share|improve this answer













            Really easy to solve, and does not require Multiple Page Controllers -- Just use once



            Create a class variable (not an instance variable) and use that as your flag to ensure that your call to reloadRootControllers is only ever called once.



            static NSString* hasLaunchedIfNotNullString = NULL;

            - (void)awakeWithContext:(id)context
            {
            if(hasLaunchedIfNotNullString == NULL)
            {
            //START Code which gets executed once
            hasLaunchedIfNotNullString = @"";

            ...
            [WKInterfaceController reloadRootControllersWithNames:YOUR_ARRAY contexts:CONTEXTS];
            // END code which gets executed once
            }
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 26 '15 at 4:14









            Clint JohnsonClint Johnson

            522




            522













            • Using a string field as a flag is generally a bad idea.

              – Aleks N.
              Jul 10 '15 at 9:30



















            • Using a string field as a flag is generally a bad idea.

              – Aleks N.
              Jul 10 '15 at 9:30

















            Using a string field as a flag is generally a bad idea.

            – Aleks N.
            Jul 10 '15 at 9:30





            Using a string field as a flag is generally a bad idea.

            – Aleks N.
            Jul 10 '15 at 9:30


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28954007%2fpage-based-reloadrootcontrollerswithnames-on-launch-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga