Question

With the following code:

MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];
//(Yes we are not using ARC yet - kills me)

the view presents but it does not load before fully sliding up to the top. The Nav controller does load properly and you see it slide all the way up. However it's just a frame. In other words, you can see the presenting view controller as the nav controller slides up into place - THEN the mMVC loads.

Thanks for the help!

Was it helpful?

Solution

Your problem is that you are trying to create a UINavigationController while using it as the UINavigationController rootviewcontroller. Fixing this line :

UINavigationController *mMNavVC = [[UINavigationController alloc] 
initWithRootViewController:mMNavVC];

to this :

MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc]   initWithRootViewController:mMVC];

will load the modal view controller before showing it.

OTHER TIPS

MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[app window] rootViewController].navigationController pushViewController: mMNavVC animated:YES];
[mMVC release];
[mMNavVC release];

Try adding a line where you access that vc's view, i.e.

MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
mMVC.view.backgroundColor = [UIColor whiteColor];
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];

This is kind of a workaround for a problem that your viewController's view doesn't get loaded before navigationController's viewDidAppear method is called. If what I posted doesn't work, the problem is elsewhere. Just try it and tell if it's ok now. :)

OK. Everybody gets a 1up for their answers because they were all helpful to me.

LucOlivierDB gets the check mark because that was just a stupid thing for me to not have seen.

!!NOTE:!! As it turns out my real problem as this line of code:

self.view.backgroundColor = [UIColor clearColor];

Someone thought it would be clever to have all the views inherit the background by making the view transparent. So when it drew the view it was drawing it transparent. Since the was not considered done drawing until the modal action was done you could see the view beneath it before that. Thanks guys. You call made me think and learn!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top