Page Based “reloadRootControllersWithNames:” on launch loop?
- (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
add a comment |
- (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
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
add a comment |
- (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
- (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
ios watchkit apple-watch
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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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.
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 callingreloadRootControllersWithNames
twice once inawakeWithContext
of myMainInterfaceController
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
add a comment |
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.
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
add a comment |
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])
}
add a comment |
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
}
}
Using a string field as a flag is generally a bad idea.
– Aleks N.
Jul 10 '15 at 9:30
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 callingreloadRootControllersWithNames
twice once inawakeWithContext
of myMainInterfaceController
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
add a comment |
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.
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 callingreloadRootControllersWithNames
twice once inawakeWithContext
of myMainInterfaceController
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
add a comment |
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.
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.
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 callingreloadRootControllersWithNames
twice once inawakeWithContext
of myMainInterfaceController
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
add a comment |
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 callingreloadRootControllersWithNames
twice once inawakeWithContext
of myMainInterfaceController
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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])
}
add a comment |
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])
}
add a comment |
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])
}
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])
}
answered Nov 25 '18 at 5:51
Richie HyattRichie Hyatt
1,50911613
1,50911613
add a comment |
add a comment |
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
}
}
Using a string field as a flag is generally a bad idea.
– Aleks N.
Jul 10 '15 at 9:30
add a comment |
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
}
}
Using a string field as a flag is generally a bad idea.
– Aleks N.
Jul 10 '15 at 9:30
add a comment |
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
}
}
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
}
}
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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