可以直接從按鈕連接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