私はビューと、とりわけボタンを表示しています。ユーザーがボタンを押すと、次のコードが実行されます。iOS - 予想外にUIAlertViewが終了する
- (IBAction) goToPhotoViewControllerView:(id) sender{
alert = [[UIAlertView alloc] initWithTitle:@"Por favor, aguarde" message:@"Carregando imagens"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alert show];
if(alert != nil) {
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-45);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
}
dispatch_async(dispatch_get_global_queue(0, 0), ^{
//Do a lot of stuff here
PhotoViewController *photoViewControllerView = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController" bundle:nil];
[iosDao selectComics];
[photoViewControllerView startWithComic:[[iosDao.comics lastObject] idComic] numPanels:[[[iosDao.comics lastObject] panels] count]];
photoViewControllerView.navigationItem.title = @"Comics";
[iosDao release];
[[self navigationController] pushViewController:photoViewControllerView animated:YES];
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
});
}
何が起こるかというと、ほとんどの時間は、全体の非同期コードは、警告メッセージを却下し、走る、ということです。しかし、警告メッセージが消えた後、画面はまだ2〜3秒間凍ったままになってから次のviewController(photoViewControllerView)にプッシュされます。私はなぜそれが起こっているのか分かりません。私は警告メッセージが必要なだけ長く続くことを望んでいます。何か案は?
ありがとうございます!
ハム、意味があります。しかし、私に聞かせてください。これは、PhotoViewControllerが非同期に割り当てられていることを意味しますか? PhotoViewControllerがロード完了した直後に、最後の2行(アラートの解除と解放を伴うもの)に到達してはなりません(この最後のコードがアラートが解除される前にコードの途中にある場合)。 –
私はあなたが言ったことを試してみました。それはうまくいきませんでした。私は、Dismiss行をPhotoViewControllerのviewWillAppearメソッドの最後の行に置きます。しかし、私が夢中になっているのは、それがその行に到達し、(予期したとおりに)警告を消してから、実際にPhotoViewControllerビューに移動する前に約3〜4秒間画面がフリーズすることです。私は、viewWillAppearの最後の行に達すると直ぐに、新しいビューを右端に表示する必要があると考えました。しかし、それはできません。前のビューは移動前に約2〜3秒間フリーズします。誰かが何か手掛かりを持っているのですか? –