可以直接从按钮连接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];
});
});
}
我没有使用NSURLConnection,所以第二个选项对我来说会更好。我不需要等待连接,我需要等待第二个视图控制器(蓝色)。在那个课上,我从互联网下载了一些图像,所以如果我按下主视图控制器上的按钮,它需要显示加载HUD,并且在加载蓝色视图控制器图像后,HUD需要消失,而蓝色需要消失弹出。 – Shinonuma 2013-03-22 09:47:17
问题是,你给“秒”,但我不知道下载所有图像需要多长时间... – Shinonuma 2013-03-22 09:48:35
任何机会,你是否使用一些“框架”(例如ASIHTTPRequest)来下载你的图像?如果是这样,那么应该有一些方法或块,以便在连接完成后可以执行应该执行的操作。我的观点是,由于您正在下载图像,因此您应该关闭进度HUD并在下载后推入蓝屏;您不应该使用选项2,因为完成下载的时间可能会有所不同。 – neilvillareal 2013-03-22 12:32:07