2013-05-17 43 views
0

我需要在應用程序開始時顯示「加載屏幕」(只是一個圖像),當應用程序從網絡獲取所有需要的數據時,將顯示第一個視圖控制器。我已經succeded通過設置自己黑屏「爲Default.png」爲「LoadingScreen.png」做和iPhone加載屏幕直到網頁請求完成

(重新命名爲爲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預計。

回答

0

您可能需要考慮使用塊,以便消除該隨機延遲。我也會考慮從你的第一個視圖來調用它,而不是從根開始(刪除警告):

//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 
    }); 
});