0

我有 11 个 UIView,每个都设置了一个手势识别器。这个 UIView 在可变数组中,每个都有一个标签。如何将按下的 UIView 标记传递给方法选择器?

viewIcone.userInteractionEnabled = YES;
viewIcone.tag = index;    

UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self    action:@selector(touchUp:)];
tap.delegate = self;
[viewIcone addGestureRecognizer:tap];
[self.arrayMutabile insertObject:viewIcone atIndex:index];

[self addSubview:viewIcone];

方法选择器的实现是:

-(void) touchUp: (UITapGestureRecognizer *) gestureRecognizer{

   NSInteger tag = [self.arrayMutabile indexOfObject:self.viewIcone];
   NSLog(@"the tag is %d", tag);
}

我总是离开10。哪里错了?提前致谢

4

1 回答 1

0

UITapGestureRecognizer 有一个从其父级继承的视图属性:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer

The view the gesture recognizer is attached to. (read-only)

@property(nonatomic, readonly) UIView *view
Discussion
You attach (or add) a gesture recognizer to a UIView object using the addGestureRecognizer: method.

Availability
Available in iOS 3.2 and later.
Declared In
UIGestureRecognizer.h

这将是被点击的视图,您可以从那里检索标签。

于 2012-04-11T08:29:31.757 回答