2012-04-11 73 views
0

我有11個UIView,每個都設置了一個手勢識別器。這個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錯誤在哪裏? 在此先感謝

回答

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 

這將是被竊聽的觀點,你可以從那裏獲取的標籤。

+0

這個幫助嗎?如果是這樣,你應該接受答案,如果沒有,我可以擴展它。 – Diziet 2012-04-12 08:27:22