UITextView beginningOfDocument returns nil
cocoa-touch, objective-c, uitextview
Solution
This is about a month late, but make sure you have the "selectable" property enabled in Interface Builder.
Credit: http://jon-nolen.blogspot.com/2013/10/uitextview-returns-nil-for-uitextinput.html
Problem
I have to get the position on the screen of a string contained in a `UITextView`. To do that, I tried to get the corresponding UITextPosition(s). The problem is that the `UITextView` method `beginningOfDocument` returns `nil` (same for `endOfDocuement`). Could someone explain me why? And which solution I could use. My code looks like this: ``` - (UITextRange *)getRangeOfString:(NSString *)string inTextView:(UITextView *)tv { UITextPosition *beginning = [tv positionFromPosition:tv.beginningOfDocument offset:[tv.text rangeOfString:string].location]; UITextPosition *end = [tv positionFromPosition:beginning offset:[tv.text rangeOfString:string].length]; return ([tv textRangeFromPosition:beginning toPosition:end]); } ```