2012-08-29 53 views
2

我想在顯示啓動畫面時從Web服務加載一些數據。在顯示啓動畫面時從webservice加載數據

我想使用下面的代碼,但我仍然無法達到合適的解決方案。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    [self backgroundtask]; 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]   autorelease]; 
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"Default.png"]; 
    [self.window addSubview:splashView]; 
    [self.window bringSubviewToFront:splashView]; 

    ViewController *masterViewController = [[[ViewController alloc]   initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease]; 
    self.window.rootViewController = self.navigationController; 
    [self.window makeKeyAndVisible]; 
} 
+0

使用上述代碼有什麼錯?它不起作用嗎?如果有性能問題。你用儀器測量過嗎? – 0x8badf00d

回答

1

如果你想顯示啓動畫面只是把名爲「爲Default.png」到資源的圖像文件。在任何視圖加載之前,該應用程序會在啓動時自動顯示。並已在didFinishLaunchingWithOptions有你的代碼的其餘部分

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
[self backgroundtask]; 
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]   autorelease]; 


ViewController *masterViewController = [[[ViewController alloc]   initWithNibName:@"ViewController" bundle:nil] autorelease]; 
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease]; 
self.window.rootViewController = self.navigationController; 
[self.window makeKeyAndVisible]; 
} 
1

這樣做:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]   autorelease]; 
    //No need of splash View as u add Default.png to bundle and application will autimatically take it as Launch Image 
    [self backgroundtask]; 
    ViewController *masterViewController = [[[ViewController alloc]   initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease]; 
    self.window.rootViewController = self.navigationController; 
    [self.window makeKeyAndVisible]; 
} 
相關問題