我有一个视图,其中包含一个按钮。当用户按下按钮,下面的代码被执行: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];
});
}
什么情况是,大部分的时间,整个异步代码运行,驳回警报消息。但是,在警报消息解除后,屏幕在推到下一个viewController(photoViewControllerView)之前仍然保持冻结状态约2或3秒。我不知道为什么会这样。我希望警报消息只要需要就保持。有任何想法吗?
预先感谢您!
胡姆,这是有道理的。但让我问你。这是否意味着PhotoViewController被异步分配?我的意思是,不应该在PhotoViewController完成加载后(最后一个在代码中间,在警告解除之前的一段时间内)完成最后两行(具有警告解除和释放的行)? –
我尝试了你所说的,但它没有奏效。我把解雇线作为PhotoViewController的viewWillAppear方法的最后一行。然而,让我疯狂的是,它到达了这条线,解除了警报(如预期的那样),然后,在实际移动到PhotoViewController视图之前,它冻结屏幕大约3或4秒。我认为,只要viewWillAppear的最后一行到达,新的视图将不得不在此后显示。但它并没有。移动前,前一个视图冻结约2或3秒。有谁知道为什么? –