メモリ エラーでクラッシュするアプリがあります。ゾンビをオンにすると、デバッガーで次のメッセージが表示されます。
Sample page based application (xcode template)[32224:f803] ***
-[DataViewController respondsToSelector:]: message sent to deallocated instance 0x6895050
これは、スクロール ビューと、スクロールとダブルタップをサポートするイメージビューを追加したときに発生します。(シミュレーターで)ページ間を移動するためにダブルクリックしてすばやくクリックすると、最終的にクラッシュが発生します。
再現するには: Xcode 4.2 を使用して、新しいプロジェクト、ページ ベースのアプリケーションを作成します。
次のようにgestureRecognisersを設定するコードをコメントアウトして、RootViewController.mを変更します(スクロールビューのダブルタップジェスチャを使用できるようにするため):
// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
//self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
問題の原因となる、完全に変更された DataViewController.m を次に示します。Xcode テンプレートを使用してプロジェクトを作成し、DataViewController.m のコードを置き換え、インターネットから適切な画像をダウンロードして (私はhttp://images.apple.com/home/images/hero.jpgを使用しました)、プロジェクトと問題を再現できるはずです。
DataViewController.m の新しいコード
//
// DataViewController.m
// Sample page based application (xcode template)
//
//
#import "DataViewController.h"
@interface DataViewController() {
UIImageView *_imageView;
UIScrollView *_scrollView;
}
@end
@implementation DataViewController
@synthesize dataLabel = _dataLabel;
@synthesize dataObject = _dataObject;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer *tapgr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
tapgr.numberOfTapsRequired = 2;
_scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
[self.view addSubview:_scrollView];
[_scrollView addGestureRecognizer:tapgr];
_scrollView.delegate = self;
UIImage *image = [UIImage imageNamed:@"hero.jpg"];
_imageView = [[UIImageView alloc]initWithImage:image];
[_scrollView addSubview: _imageView];
_scrollView.contentSize = image.size;
_scrollView.maximumZoomScale = 3.0;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return _imageView;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.dataLabel.text = [self.dataObject description];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)doubleTap:(UITapGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded) {
if (_scrollView.zoomScale > _scrollView.minimumZoomScale)
[_scrollView setZoomScale:_scrollView.minimumZoomScale animated:YES];
else
[_scrollView setZoomScale:_scrollView.maximumZoomScale animated:YES];
}
}
@end
クラッシュするまでクリックしてみてください。この問題を回避する方法はありますか?
ポール