View Full Version : Why is this code crashing my program
cis4life
Jun 17, 2009, 12:13 PM
I have this code snippet but its crashing the application.
- (void)viewDidLoad
{
BlueViewController *blueController = [[BlueViewController alloc] initWithNibName:@"BlueView" bundle:nil];
self.blueViewController = blueController;
[self.view insertSubview:blueController.view atIndex:0];
[blueController release];
}
This line in the code is making the app crash...
[self.view insertSubview:blueController.view atIndex:0];
if i commet it out, the app works, when I comment it back in, it breaks?
Why?
Cedric
dejo
Jun 17, 2009, 12:18 PM
Crashes how? Are you getting a run-time error? We need more details.
cis4life
Jun 17, 2009, 12:25 PM
the programs just stops and says it stopped unexpectedly. When I remove that line, the program loads up, but of course the view doesn't load (i commeted out that line)
Cedric
robbieduncan
Jun 17, 2009, 12:34 PM
Probably because you are trying to insert a UIViewController instead of a UIView. Check the documentation for UIView.
Saladinos
Jun 17, 2009, 12:35 PM
Try
[self.view insertSubview:[self.blueViewController view] atIndex:0];
BlackWolf
Jun 17, 2009, 04:20 PM
is that line you posted the exact line the app CRASHES or is it just the one causing your crash?
because I guess the release-line is the real bad guy. Because insertSubview probably sends a retain message to the VIEW, but not the viewController ... or so I guess. something like that.
dejo
Jun 17, 2009, 04:34 PM
the programs just stops and says it stopped unexpectedly.
No error messages or hints in the crash log?
NeilBright
Jun 10, 2010, 03:52 PM
Hi,
Did anyone find a solution to this?
Thanks.
seepel
Jun 11, 2010, 02:08 PM
Is it possible that in the nib the view controller isn't connected to the view?
Thomas Harte
Jun 11, 2010, 03:51 PM
Is it possible that in the nib the view controller isn't connected to the view?
I second this suggestion. I believe insertSubview:nil will crash.
A more useful thing to do would be to run in the simulator using GuardMalloc and post everything that appears on the console.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.