如何将UIView的标签传递给方法选择器?

时间:2012-04-11 08:22:28

标签: iphone uiview selector uigesturerecognizer

我有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.哪里错了? 提前致谢

1 个答案:

答案 0 :(得分:0)

UITapGestureRecognizer有一个view属性,它继承自它的父级:

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

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