我想显示一个带有活动指示器的启动屏幕视图,以便在进入我的应用程序之前从服务器加载一些信息。以下是我的做法:
- (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;
}
在 FeedViewController.m 中,我做了这样的事情:
- (void)viewDidLoad
{
// load data from a server
[self performSelector:@selector(dismissSplashScreen) withObject:nil afterDelay:0.0];
}
这段代码在 iOS6 上运行得很好,但是当我用 iOS5 测试它时,带有活动指示器旋转的初始屏幕并没有消失。我怀疑我可能会以错误的方式实现启动画面。(但我不明白为什么这在 iOS6 中有效?)