small medium large xlarge

Back to: All Forums  iOS Recipes
01 Jun 2011, 14:39
Jonathan Lundell (5 posts)

I implemented the splash screen by putting this in my app delegate:

    PRPSplashScreen *splashScreen = [[[PRPSplashScreen alloc] init] autorelease];
    splashScreen.showsStatusBarOnDismissal = YES; 
    splashScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    [self.navigationController presentModalViewController:splashScreen animated:NO];

…not bothering with a delegate. It works fine, except that my nav & tool bars, set up in my main view controller’s ViewWillAppear, didn’t show up (the bars are blank). Moving the bar-init logic to ViewDidAppear fixes the problem.

I can live with that, but I’m curious as to why it happens.

04 Jun 2011, 06:07
Matt Drance (54 posts)

Recalling this part of the chapter:

bq. This timing is important: the root view controller won’t properly present a modal view controller if its own view isn’t in place.

… you may have to force the issue by adding a benign self.navigationController.view to your code. Modal stacks on launch are tricky that way.

There’s also a bug in PRPSplashScreen (fixed since the last beta) that can cause the parent view to never receive viewWillAppear:. Here’s the fix:

~~~ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; SEL didAppearSelector = @selector(splashScreenDidAppear:); if ([self.delegate respondsToSelector:didAppearSelector]) { [self.delegate splashScreenDidAppear:self]; } [self performSelector:@selector(hide) withObject:nil afterDelay:0]; } ~~~

The change is in the performSelector: wrapping. Dismissing a modal view (or popping one off the nav stack, etc) from within the scope of viewDidAppear: makes UIKit angry, so we push hide off to the next runloop iteration. Earlier copies of the code just called hide directly.

07 Jun 2011, 15:33
Jonathan Lundell (5 posts)

FYI, switching to performSelector fixed my problem; no need for the view reference.

07 Jun 2011, 16:17
Jonathan Lundell (5 posts)

But. The problem now is that I get a flash of my main view before the splash screen goes up, which sort of ruins the effect. It appears that both the main-view ViewWillAppear and ViewDidAppear are getting called before the splash screen appears. Which seems odd, since you’d think that only the hide would be affected by the change.

09 Jun 2011, 19:23
Matt Drance (54 posts)

Can you paste the entire contents of your appDidFinishLaunching method, and tell us what you’re testing on? Thanks Jonathan.

02 Sep 2011, 02:04
Anthony Thompson (1 post)

I’m having the same issue (looks great in sim, but main window flashes before transition); may I jump in here with my info?

My didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    CFAbsoluteTime jim = CFAbsoluteTimeGetCurrent ();
    [self.window addSubview:self.splashScreen.view];
    self.splashScreen.showsStatusBarOnDismissal = YES;
    self.splashScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    //kqVC is custom table view controller
    [self.kqVC presentModalViewController:splashScreen animated:NO];
    [self.window makeKeyAndVisible];
    NSLog(@"LAUNCH %f",CFAbsoluteTimeGetCurrent () - jim);
    return YES;

I’m trying this on iPhone 4 running 4.3.5 BL1.


15 Sep 2011, 03:05
Matt Drance (54 posts)

Looks like you’re adding the splash screen’s view to the window up top, when you should be adding the main/root VC’s view. Right now you’re presenting the splash screen onto itself, which is peculiar.