I'm attempting to write a multiview app in iOS and really having a bit of a tough time... I've setup a new project and I've got a rootViewController being launched by the appDelegate. In turn, the rootViewController attempts to load and display my first content view, although I seem to have fallen into some kind of infinite loop, I'm hoping someone here may have a hunch as to why...
-(void)viewDidLoad
{
// Load up new instance of view
TopLevelViewController *topLevelController =
[[TopLevelViewController alloc] initWithNibName:@"TopLevelView" bundle:nil];
// Hand off viewController reference to root controller
self.topLevelViewController = topLevelController;
// Display the view
[self.view insertSubview:topLevelController.view atIndex:0];
// Release viewController
[topLevelController release];
[super viewDidLoad];
}
Above is my rootViewController viewDidLoad: method, although every time it executes insertSubview, it seems to return to the top and perform the whole thing again. I'm a bit confused as I've based this code almost identically on a tutorial I followed and it ran beautifully...which leads me to think the problem must be elsewhere, although I couldn't possibly think where.
Appreciate any insight!
I ran into the same issue and cost a while to figue out.
When self.view doesn't exist, iOS will call loadview/viewdidload and try to create the view. this cause the deadloop. In my case, I didn't call [super loadView] in my loadView, and cause this problem.
See this discussion http://forums.macrumors.com/showthread.php?t=552520
Set a breakpoint on viewDidLoad
, continue a few times, then grab the backtrace and post it.
Also, add NSLog(@"%@ self is %p", NSStringFromSelector(_cmd), self);
to the beginning of your viewDidLoad
. It might be that you have created a sort of "infinite mirrors" configuration of nib files; if the hex number keeps changing, that'll be different instances of your view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With