Reputation: 1602
I would like to show a splash screen view with activity indicator to load some information from a server before entering inside my app. Below is how I do it:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FeedViewController *feedViewController = [[FeedViewController alloc] initWithNibName:@"FeedViewController" bundle:nil];
MenuViewController *menuViewController=[[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
IIViewDeckController* deckController = [[IIViewDeckController alloc] initWithCenterViewController:self.navController leftViewController:menuViewController rightViewController:nil];
deckController.panningMode=IIViewDeckNoPanning;
deckController.panningView=menuViewController.view;
self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
// show splash screen until data is loaded
SplashScreenViewController *controller = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenViewController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[feedViewController presentModalViewController:controller animated:NO];
return YES;
}
In FeedViewController.m, I did something like this:
- (void)viewDidLoad
{
// load data from a server
[self performSelector:@selector(dismissSplashScreen) withObject:nil afterDelay:0.0];
}
This code works very well with iOS6, but when I tested it with iOS5 the splash screen with activity indicator spinning just does not disappear. I suspect I might implement a splash screen in a wrong way. (But I don't understand why this works in iOS6?)
Upvotes: 0
Views: 305
Reputation: 1602
I solved this problem myself by using a bool variable to check whether the splash screen should be shown. The code for showing the splash screen is moved to viewDidLoad
of FeedViewController instead.
This approach seems to work well for both iOS5 and iOS6.
Upvotes: 1