I get two of the same root view

I am testing my app on iphone and the software version is 4.2.1. I find some problems happened when switching from a customer launchview controller to the rootview controller. The code is as below:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
launchViewController = [[[LaunchImageTransition alloc] initWithNibName:@"LaunchView_iphone" bundle:nil controller:self.viewController animation:UIModalTransitionStyleCrossDissolve] autorelease];

self.window.rootViewController = launchViewController;

In the "LaunchImageTransition.m":

//do some initial work
[self presentModalViewController:self.rootViewController animated:YES];

The rootViewController is initialed in the "MainWindow.xib".

When I test on the iphone simulator, everything is ok. But when I test on the real device, I find that the viewDidAppear method of the rootViewController is called twice while the viewDidload method is called once. This result in two of the same view。

I want to know why this only happened on real device and how to fix it?


I think that the problem is that you are using the view system in a way that it is not the way it has been thought it should be used. My advice is to change the way you present your views.

I don't know if you have to do this exactly this way, but I think that a better way to go is to let the rootViewController as it should be, like the mainViewController.

At the end of the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method you can present the launchView as modal on the mainViewController.

    [mainViewController presentModalViewController: launchViewController animated:YES];

And on the viewWillAppearMethod or viewDidAppearMethod of the mainViewController you can dismiss the launchViewController.

    -(void) viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [self dismissModalViewControllerAnimated:YES];

I hope it helps...

Need Your Help

Should I use interface builder or not?

iphone xcode interface-builder

I'd like to know more about the pros and cons of using interface builder when developing iPhone/iPad apps.

Position link with CSS?

html css hyperlink

i have the following HTML code: