ボタンから直接セグエを接続する代わりに、View Controller クラスからセグエを接続できます。セグエに名前を付けてください。この名前は、後で呼び出すために必要です。
IBAction
次に、ロードしているものを最初にロードする最初のボタンにボタンを接続できます。読み込みが完了したら、プログレス HUD を閉じて、セグエを呼び出すことができます。
- (IBAction)loadStuff:(id)sender
{
[SVProgressHUD showWithStatus:@"Loading"];
[self retrieveStuff];
}
- (void)retrieveStuff
{
// I'll assume you are making a NSURLConnection to a web service here, and you are using the "old" methods instead of +[NSURLConnection sendAsynchronousRequest...]
NSURLConnection *connection = [NSURLConnection connectionWith...];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Do stuff with what you have retrieved here
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:@"PushSegueToBlueScreen"
sender:nil];
}
最初に何が起こるかをシミュレートしたいだけなら、これを試すことができます:
- (IBAction)loadStuff:(id)sender
{
[SVProgressHUD showWithStatus:@"Loading"];
[self retrieveStuff];
}
- (void)retrieveStuff
{
[NSTimer scheduledTimerWithTimeInterval:2 // seconds
target:self
selector:@selector(hideProgressHUDAndPush)
userInfo:nil
repeats:NO];
}
- (void)hideProgressHUDAndPush
{
// Do stuff with what you have retrieved here
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:@"PushSegueToBlueScreen"
sender:nil];
}
編集:単一の画像をダウンロードするために、この GCD ブロックを試すことができます。複数の画像のダウンロードをサポートできるように、これをいじるだけでよいと思います。
- (IBAction)loadStuff:(id)sender
{
[SVProgressHUD showWithStatus:@"Loading"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
// ... download image here
[UIImagePNGRepresentation(image) writeToFile:path
atomically:YES];
dispatch_sync(dispatch_get_main_queue(),
^{
[SVProgressHUD dismiss];
[self performSegueWithIdentifier:@"PushSegueToBlueScreen"
sender:nil];
});
});
}