Ok so i have a uitableview and when an item is selected it segues to a new view controller to show an image (inside of a uiscrollview). 图像开始从 prepareforsegue 的 dispatch_queue 中下载。需要明确的是,我正在主队列中进行所有 UI 更新。问题是,如果我足够快地点击后退按钮,那么我的程序会因 exc_bad_address 崩溃。我认为问题必须处理 zoomToRect 动画:是的,因为当我将动画设置为 NO 时,我无法让它崩溃。加上下面的调用堆栈处理动画。解决此问题的最佳方法是什么,是否有更好的方法来完成我需要做的事情?
同样在调试问题时打印“块已完成”,然后不久后崩溃。
这是调用的方法。它在 prepareForSegue 中目标控制器的设置器中调用。
-(void) updateDisplay {
dispatch_queue_t queue = dispatch_queue_create("Load Flickr Photo", NULL);
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:spinner];
[spinner startAnimating];
dispatch_async(queue, ^{
UIImage *image = [FlickrFetcher imageForPhoto:self.currentPhoto format:FlickrPhotoFormatLarge];
dispatch_async(dispatch_get_main_queue(), ^{
self.navigationItem.rightBarButtonItem = nil;
self.imageView.image = image;
self.title = [FlickrFetcher titleForPhoto:self.currentPhoto];
CGAffineTransform transform = CGAffineTransformMakeScale(1.0, 1.0);
self.imageView.transform = transform;
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
self.scrollView.maximumZoomScale = 4.0;
self.scrollView.minimumZoomScale = .2;
self.scrollView.zoomScale = 1;
self.scrollView.contentSize = self.imageView.bounds.size;
//i think problem is here
[self.scrollView zoomToRect:self.imageView.frame animated:YES];
NSLog(@"Block completed");
});
});
}