Reputation: 111
textView.selectedRange = NSMakeRange(0, 0);
This has no effect on where the cursor is placed.
I then used a breakpoint and typed in po textView.selectedRange
in the debugger.
The result was:
(lldb) property 'selectedRange' not found on object of type 'UITextView *'
Upvotes: 1
Views: 597
Reputation: 598
Since UITextView inherits from UIResponder. So, you can call the -becomeFirstResponder method on your text view, which will cause it to become the first responder and begin editing:
[textView becomeFirstResponder];
After that, you can selectedRange of UITextView.
[textView setSelectedRange:NSMakeRange(0, 10)];
Added the UITextView delegate in View controller.
@interface SecondViewController : UIViewController<UITextViewDelegate>
Assign the property to text view.
@property (strong, nonatomic) IBOutlet UITextView *textView;
And selected the text range in textview.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.textView becomeFirstResponder];
[self.textView setSelectedRange:NSMakeRange(0, 10)];
}
Upvotes: 1