Skip to content

Instantly share code, notes, and snippets.

@CH3COOH
Last active December 17, 2015 20:59
Show Gist options
  • Select an option

  • Save CH3COOH/5671275 to your computer and use it in GitHub Desktop.

Select an option

Save CH3COOH/5671275 to your computer and use it in GitHub Desktop.
iOSで遅延起動させてみた その2 ローディング画面->起動画面への遷移
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// ローディング画面
self.viewControllerA = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
// 起動画面とする
self.viewControllerB = [[[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil] autorelease];
// まずはローディング画面を表示するでござる
self.window.rootViewController = self.viewControllerA;
[self.window makeKeyAndVisible];
return YES;
}
- (void) startApplication {
// ホーム画面に切り替えるでござる
self.window.rootViewController = self.viewControllerB;
}
// ローディング画面のロード
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://ch3cooh.jp/"]];
[NSURLConnection sendAsynchronousRequest:req
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *res, NSData *data, NSError *error) {
// なんか重たい処理とかやってる
[NSThread sleepForTimeInterval:5];
dispatch_async(dispatch_get_main_queue(), ^{
id appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate performSelector:@selector(startApplication)];
});
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment