2014-10-13 2 views
-4

TextView의 TapGesture에서 태그 값을 얻습니다. 이제 내 질문은 텍스트에서 문자열 값을 얻는 방법입니다. 이것은 당신이 exaclty 텍스트 뷰의 텍스트를해야하는 경우,이 코드가 작동하고 내가 테스트 한태그에서 값을 얻는 방법

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

텍스트 뷰에 탭 제스처를 추가 위의 방법으로 내 코드

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

'UITextView' 클래스 레퍼런스를 보았습니까? – Droppy

+0

텍스트 뷰에서 텍스트를 가져와야합니까 –

+0

예. 나는 textview의 가치를 원합니다.하지만 Textview는 다른 수업에 있습니다. – user3651677

답변

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

입니다 이제는 잘 작동합니다.