わかりましたので、uitableview があり、アイテムが選択されると、新しいビュー コントローラーにセグエして画像を表示します (uiscrollview 内)。イメージは、prepareforsegue から dispatch_queue でダウンロードを開始します。明確にするために、メイン キューですべての UI 更新を行っています。問題は、戻るボタンをすばやく押すと、プログラムが exc_bad_address でクラッシュすることです。問題は zoomToRect animation:YES に対処する必要があると思います。なぜなら、アニメーションを 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");
});
});
}