从UITextView中获取单词

我试图从水龙头中得到一个字。 以下函数的sender来自UITextView句子上的UIGesture

 - (IBAction)printWordSelected:(id)sender { NSLog(@"Clicked"); CGPoint pos = [sender locationInView:self.view]; UITextView *_tv = sentence; NSLog(@"Tap Gesture Coordinates: %.2f %.2f", pos.x, pos.y); //eliminate scroll offset pos.y += _tv.contentOffset.y; //get location in text from textposition at point UITextPosition *tapPos = [_tv closestPositionToPoint:pos]; //fetch the word at this position (or nil, if not available) UITextRange * wr = [_tv.tokenizer rangeEnclosingPosition:tapPos withGranularity:UITextGranularityWord inDirection:UITextLayoutDirectionRight]; NSLog(@"WORD: %@", [_tv textInRange:wr]); } 

这是我已经有的,但它打印出来的单词为NULL

“尝试更改pos pos = [发件人locationInView:_tv],然后删除pos.y调整 – rmaddy”