0

我在 UIscroll 视图中有许多 UItextViews。当用户按下按钮时,他应该能够点击这些 UItextView 之一,并且根据他触摸的文本视图,将选择其中的文本。由于我的 UItextViews 编号取决于每个用户,因此我为它们分配了一个整数的标签:1、2、3。然后我使用点击手势来检测被触摸视图的标签:

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 总是等于零。为什么是这样?

4

1 回答 1

0

我终于想出了如何确定标签:

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

...

基本上这是确定它的代码:

[(UIGestureRecognizer *)recognizer view].tag
于 2013-01-23T16:46:05.637 回答