我有一个视图,上面还有一个按钮。当用户按下按钮时,将执行以下代码:
- (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需要花费一些时间来加载(您可以使用Instruments进行确认吗?)。由于PhotoViewController是您自己的类,因此您可以让它有一个委托,使主视图控制器(消除UIAlert的那个)成为PhotoViewController实例的委托,并让PhotoViewController调用委托以在准备就绪时通知它和/或可见,例如在
- (void)viewWillAppear:(BOOL)animated