您可以从视图控制器类连接segue,而不是直接从按钮连接segue。确保你给 segue 一个名字,因为你需要这个名字,这样你以后可以调用它。
然后,您可以将您的按钮连接到IBAction
第一个,该按钮将首先加载您正在加载的内容。加载完成后,您可以关闭进度 HUD 并调用 segue。
- (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];
});
});
}