I am trying to put a first launch view. I already tried some stuff but that won\'t work.
Here is what I have:
- (BOOL)application:(UIApplication *)a
There are a few things wrong with your implementation of application:didFinishLaunchingWithOptions:
which is most definitely the cause of your troubles.
I recommend that you read through a few tutorials on getting started with iOS development as these are fundamental concepts you will need to grasp if you intend on doing any serious development in the future.
That being said, the following code should see you right:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
UIViewController *viewController = nil;
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"yourCondition"])
{
//launch your first time view
viewController = [[viewController alloc] initWithNibName:@"viewController" bundle:nil];
}
else
{
//launch your default view
viewController = [[viewController alloc] initWithNibName:@"defaultViewController" bundle:nil];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"yourCondition"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
[[self window] setRootViewController:viewController];
[[self window] makeKeyAndVisible];
return YES;
}
The default implementation of application:didFinishLaunchingWithOptions:
expects that you return a boolean, which is indicated by the method signature.
You are also missing the important call at the beginning of the method which sets up the main NSWindow
for your application to be presented.
As pointed out by @matt, your code expects that you have a property on you AppDelegate which would hold your reference to viewController
. From what you mentioned about the compilation error, it would seem that you do not have this relationship setup. As it happens, you might not need this anyway as you can essentially achieve the same thing by setting the rootViewController
property of your NSWindow
.
Again, I would recommend that you read up on some beginner tutorials for iOS development or purchase a decent book as issues like this are fairly fundamental. If you're having troubles with this alone, you will only find yourself more confused and likely to require assistance one you start delving into more complex code.