One thing that you are doing wrong is that fractionOfDistanceBetweenInsertionPoints:
should not be zero. It is a result parameter, so it should be the address of a CGFloat
or NULL
if you don't care.
CGPoint touchPoint = [sender locationInView:self.txtView];
CGFloat fraction = 0;
NSUInteger charIndex = [self.txtView.layoutManager
characterIndexForPoint:touchPoint
inTextContainer:self.txtView.textContainer
fractionOfDistanceBetweenInsertionPoints:&fraction];
You may not be interested in the fractionOfDistanceBetweenInsertionPoints:
later, but it may be able to help you diagnose this issue. The point you are passing in may be ambiguous and it will help you to see that.