我们如何从其标签中获取价值

时间:2014-10-13 06:43:08

标签: ios objective-c

我从Textview的TapGesture获取标签值。现在我的问题是我们如何从文本中获取字符串值。这是我的代码

-(void)contactselected:(UITapGestureRecognizer *)gestureRecognizer
{
    UITextView *text = (UITextView *)gestureRecognizer.view;
    NSLog(@"%ld",(long)text.tag);
    NSString *button=(NSString *)[gestureRecognizer.view viewWithTag:text.tag];
    NSLog(@"%@",button);
}

1 个答案:

答案 0 :(得分:1)

UITapGestureRecognizer *lTapGestureRecognizer1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contactselected:)];
lTapGestureRecognizer1.delegate=self;
[self.mDescritionTextview_ addGestureRecognizer:lTapGestureRecognizer1];

以上述方式将点击手势添加到textview

-(void)contactselected:(UITapGestureRecognizer *)gestureRecognizer
{
    UITextView *text = (UITextView *)gestureRecognizer.view;
    NSLog(@"%ld",(long)text.tag);
    NSLog(@"%@",text.text);
}

如果您需要textview中的文本,此代码将起作用,我已经测试了它现在工作正常