Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cis4life

macrumors regular
Original poster
Apr 4, 2008
216
67
I have this code snippet but its crashing the application.

Code:
- (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
 
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
 
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.
 
Is it possible that in the nib the view controller isn't connected to the view?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.