iPhone加载屏幕,直到Web请求完成

时间:2013-05-17 13:55:02

标签: objective-c loading webrequest appdelegate

我需要在应用程序启动时显示“正在加载屏幕”(只是一个图像),当应用程序从Web获取所有需要的数据时,将显示第一个viewcontroller。我已成功通过将我自己的黑屏“Default.png”设置为“LoadingScreen.png”(当然再次命名为Default.png)和

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[THWViewController alloc] initWithNibName:@"THWViewController" bundle:nil];
[self performSelector:@selector(start) withObject:nil afterDelay:5.0];
[self.window makeKeyAndVisible];
return YES;
}

- (void)start
{
self.window.rootViewController = self.viewController;
}

我会将这种随机延迟更改为api加载完成时,但这是实现它的好方法吗?因为我得到了rootviewcontroller所期望的消息。

1 个答案:

答案 0 :(得分:0)

您可能需要考虑使用块,以便消除该随机延迟。我也会考虑从你的第一个视图调用它,而不是从没有root开始(删除警告):

//show your loading screen over your first view
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // Get all the needed data

    dispatch_async( dispatch_get_main_queue(), ^{
        // do what you need to do with data and in first view
        //hide the loading screen
    });
});