Hi, I was wondering if someone could tell me what I'm doing wrong here. I'm making a simple application that I can use as a template for future projects that use nested view controllers. The code should work, or at least I thought. Here is the part of code that's causing my app to crash when I attempt to run it:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
self.firstView = aView;
//The next line, where I add the subview, is what
//is making my app crash when I try to run it
[window addSubview:firstView.view];
[aView release];
return YES;
}
The FirstViewController class has no instance variables, its .xib file just has a button linked to a function for switching between itself and the second controller. The two view controllers swap by calling a method from the delegate class that does a simple animation and replaces one view with the other.
The debugger just tells me that the app terminates due to an uncaught exception, but I don't know what I did wrong. If you need to see more of the code just ask. Help
Hi, I was wondering if someone could tell me what I'm doing wrong here. I'm making a simple application that I can use as a template for future projects that use nested view controllers. The code should work, or at least I thought. Here is the part of code that's causing my app to crash when I attempt to run it:
Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window makeKeyAndVisible];
FirstViewController *aView = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
self.firstView = aView;
//The next line, where I add the subview, is what
//is making my app crash when I try to run it
[window addSubview:firstView.view];
[aView release];
return YES;
}
The FirstViewController class has no instance variables, its .xib file just has a button linked to a function for switching between itself and the second controller. The two view controllers swap by calling a method from the delegate class that does a simple animation and replaces one view with the other.
The debugger just tells me that the app terminates due to an uncaught exception, but I don't know what I did wrong. If you need to see more of the code just ask. Help
I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
In your NIB check to make sure it has it's view property set. If it doesn't have a view add one to the NIB, then right click on the file owner (should be FirstViewController) and set the view outlet to the added view. This is a usual suspect.
Quote:
Originally Posted by bate5150
Thanks for the response.
I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
I tried that but no dice, I'm at a loss because it really seems to me like it should work. I've followed the program step by step through almost everything and it just terminates here...
In your NIB check to make sure it has its view property set. If it doesn't have a view add one to the NIB, then right click on the file owner (should be FirstViewController) and set the view outlet to the added view. This is a usual suspect.
I checked to make sure but the nib has a view and its outlet is set to the view. Also File's Owner is of the FirstViewController class so that's not the problem either.