2013-01-23 45 views
0

我在UIscroll視圖中有很多UItextViews。當用戶按下一個按鈕時,他應該能夠點擊其中一個UItextView,並根據他觸摸的文本視圖來選擇文本。由於我的UItextViews數量取決於每個用戶,我將它們分配給一個整數的標籤:1,2,3。然後,我用自來水姿態的姿態來檢測觸摸視圖的標籤:確定點擊UItextView的標籤

UITapGestureRecognizer *myLongPressRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)]; 
//[myLongPressRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)]; 
[textname addGestureRecognizer:myLongPressRecognizer]; 


- (void)leftSwipe:(UITapGestureRecognizer *)recognizer { 

id sender; 
UITextView *txtChoosen = (UITextView*) sender; 

for (UITextView* txt in textnameArray) { 

    NSLog(@"%djjjjjjj, %d", txtChoosen.tag, txt.tag); 

    if (txt.tag == txtChoosen.tag) { 

     txt.layer.borderWidth = 5.0f; 
     txt.layer.borderColor = [[UIColor whiteColor] CGColor]; 
    }else{ 

     txt.layer.borderWidth = 0.0f; 
     txt.layer.borderColor = [[UIColor whiteColor] CGColor]; 
}} 
... 

我的問題是,txtChoosen.tag總是等於零。爲什麼是這樣?

回答

0

我終於想通了如何確定標籤:

if (txt.tag == [(UIGestureRecognizer *)recognizer view].tag) { 

... 

基本上是這樣的代碼,以確定它:

[(UIGestureRecognizer *)recognizer view].tag 
+0

如果你不知道:你能接受自己回答。 – herzbube