Setting the cursor position of the UITextField
I looked at monotouch samples and tried:
var range = new NSRange(selectionStart, 1);
NumberTextField.SelectedTextRange = IndexedRange.GetRange(range);
But this throws this exception at runtime: Objective-C exception. Name: NSInvalidArgumentException Cause: - [iOS_IndexedRange asRange]: unrecognized selector posted to instance 0x7d9bd690
I've also looked at a lot of Objective-C versions, but I can't figure out how to do this on monotouch.
+3
source to share
1 answer
Ruben Macias on the Xamarin forums helped me.
entryField.BecomeFirstResponder();
var indexToSet = 3; //set cursor after the 3rd letter
var positionToSet = entryField.GetPosition(entryField.BeginningOfDocument, indexToSet);
entryField.SelectedTextRange = entryField.GetTextRange(positionToSet, positionToSet);
+2
source to share