确定tapped UItextView的标记

时间:2013-01-23 16:23:38

标签: ios xcode

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

1 个答案:

答案 0 :(得分:0)

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

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

...

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

[(UIGestureRecognizer *)recognizer view].tag