画面にいくつかのビューを追加しようとしていますが、ユーザーが画面内の他の場所に移動できるようにしたいです(パンジェスチャを使用)。
コードを使用してビューとそのコンテンツを作成しましたが、正常に機能していますが、ジェスチャレコグナイザーがアクションメソッドを呼び出せません。ビューのいずれかに触れると(レコグナイザーの1つをトリガーしようとすると)、このエラーが発生し、アプリケーションがクラッシュします。
-[UIView panThisNote:]: unrecognized selector sent to instance 0x1b0500
これは、ビューを作成し、必要な値を割り当てるコードです。
for (int i = 1; i <= self.NOP; i++)
{
UIView *stateView = [[UIView alloc] initWithFrame:CGRectMake((arc4random()%700)-100 , (20 * 91) + 378 + ((arc4random()%600)+200), 325 , 188)];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 325, 188)];
imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"L7_stickyNote_%d.png",arc4random()%4]];
int randomSign = ( arc4random()%2 == 0 ? 1 : -1 );
CGAffineTransform transform = CGAffineTransformMakeRotation( randomSign * M_PI/((arc4random()%35)+2) );
stateView.transform = transform;
[stateView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:stateView action:@selector(panThisNote:)]];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 283, 146)];
textView.text = [self.finalStates objectAtIndex:i-1];
textView.userInteractionEnabled = NO ;
textView.backgroundColor = [UIColor clearColor];
textView.textAlignment = UITextAlignmentCenter;
textView.font = [UIFont fontWithName:@"Noteworthy" size:14];
[stateView addSubview:imgView];
[stateView addSubview:textView];
[self.BGPaper addSubview:stateView];
}
よくわかりませんが、なぜこれが発生するのかはわかっていると思います(ループ内で同じ名前で作成されたオブジェクトのメモリ割り当てが原因だと思います)が、GestureRecognizersを追加してこれを修正する方法がわかりません。
誰かが私を訂正してくれるといいですね。前もって感謝します。