PDA

View Full Version : start up view




jjgraz
Apr 7, 2009, 12:32 PM
How do change the start up view so on first launch it opens the settings view? I have the application with a tab bar.....one of the tabs is a settings view which saves all the settings in NSUserDefaults. I want the application to launch and find out if for example NSUserdefault for key name is nill, if nill then load the settings view. I'm having trouble writing this in, and not exactly sure if it belongs in the ViewDidLoad of the initial first view or DidFinishingLaunching in appDelegate.....Any help on this subject would be greatly appreciated.



dejo
Apr 7, 2009, 02:42 PM
I'd say applicationDidFinishLaunching: is the proper place to put it.

jjgraz
Apr 7, 2009, 04:47 PM
So I believe I almost have it...

- (void)applicationDidFinishLaunching:(UIApplication *)application {

NSString *number1 = [[NSUserDefaults standardUserDefaults] stringForKey:@"mobilefieild"];
NSString *name1 = [[NSUserDefaults standardUserDefaults] stringForKey:@"firstnamefield"];

if ((number1 == nil) || (name1 == nil)) {
[self displayNagScreen:application];
}
else {
[self displayMyApp:application];
}

[window makeKeyAndVisible];



Above, I split the applicationDidFinishLaunching into two parts. Below, Is where they are told how to act. I just don't know how to pull up my settingsView xib in the -(void)displayNagScreen. Please help if you are able.


- (void)displayMyApp:(UIApplication *)application {

********lots of stuff here********

}

- (void)displayNagScreen:(UIApplication *)application {

********* ? *********

}

Thank you.

dejo
Apr 7, 2009, 05:07 PM
Perhaps?:
- (void)displayMyApp:(UIApplication *)application {
[window addSubview:[rootViewController view]];

********lots of stuff here********

}

- (void)displayNagScreen:(UIApplication *)application {
[window addSubview:[nagViewController view]];

********* ? *********

}

jjgraz
Apr 7, 2009, 07:09 PM
It doesn't seem to work that way. Do you think this is because im using a UITabBarController? I have a TabBarController which controls 5 tabs(5nibs) one being this nagViewController.

I also found when doing this: (note the controllers are the same in this example)

- (void)displayMyApp:(UIApplication *)application {
[window addSubview:[rootViewController view]];

********lots of stuff here********
}

- (void)displayNagScreen:(UIApplication *)application {
[window addSubview:[rootViewController view]];

********* same stuff as above here *********
}

The if else statement, seems to be running the application as the NagScreen, and functions of the app are running fine. But the same is not true for the MyApp. I'm sure the NSUserdefault keys are correct...so any ideas on that? it seems as though the if else statement is returning nil, (which should not be the case, as i have saved settings). Is there anything else to do besides what I posted for applicationDidFinishLaunching? Any thoughts on this would help a ton. Thank you.

dejo
Apr 7, 2009, 07:29 PM
it seems as though the if else statement is returning nil, (which should not be the case, as i have saved settings).
I'd put a breakpoint at the 'if" line and try to determine, using the debugger and examining your variables, why it's not evaluating the way you think it should be.

jjgraz
Apr 14, 2009, 04:23 PM
I debugged and got the if then statement working properly, and the code below does seem to work. However, I would like to modify it so the nag screen is not a new view...It should open one of the existing views, but when code for the different view is inserted, it gives me the syntax error before controller...see code below if you can help. I appreciate it.


- (void)displayMyApp:(UIApplication *)application {
[window addSubview:rootController.view];
********lots of code here*********
}


- (void)displayNagScreen:(UIApplication *)application {
[window addSubview:nagScreenController.view];
**** get an error if nagscreenController is changed to an existing controller in myapp******
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *name1 = [defaults objectForKey:@"****"];

if (name1 == nil) {
[self displayNagScreen:application];
}
else {
[self displayMyApp:application];
}

[window makeKeyAndVisible];
}

In the following example, if an existing view is inserted in the place of nagScreenController, the syntax error comes. How do I use an existing View?
Thank you.

BlackWolf
Apr 14, 2009, 04:39 PM
I don't quite get what you are trying to do.

there are two scenarios here:
first one is that you use a UITabBarController. in that case, you simply set UITabBarController's "selectedViewController" property to the view controller of your choice ^^
second one is you are NOT using a tabbar, in which case you simply add the view of the ViewController of your choice to the window.

jjgraz
Apr 14, 2009, 05:00 PM
right. here is a bit of info:

My application has a tabBarViewController with 5 tabs. It is all set up and working. In the appDelegate DidFinishLaunching method I create a possible two paths which the program may go. The first MyApp(runs the app as normal,opens tab1 on the tabbarcontroller), the second nagscreen(opens a different starting tab which users must fill in their username and details, tab5 on the tabbarcontroller).....How do I write open tab 5............When i use,

- (void)displayNagScreen:(UIApplication *)application {
[window addSubview:tab5Controller.view];
}

I get the error. Are you saying swap

[window addSubview:tab5Controller.view];
with "selectedViewController"
?

Thanks again.