带有活动指示器的启动画面在iOS6中工作正常,但在iOS5中没有

时间:2012-12-09 07:43:13

标签: ios5 ios6 splash-screen

我想在进入我的应用程序之前显示带有活动指示器的启动画面视图,以从服务器加载一些信息。以下是我的工作方式:

- (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中有效?)

1 个答案:

答案 0 :(得分:1)

我自己通过使用bool变量来检查是否应该显示启动画面来解决这个问题。显示启动画面的代码将移至FeedViewController的viewDidLoad

这种方法似乎适用于iOS5和iOS6。