Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Altering the SelectedTextRange on a UITextField appears to have no effect.
Given a UITextField named "foo," I would expect that the following code would highlight everything in my text field:
UITextRange allRange = foo.GetTextRange(foo.BeginningOfDocument, foo.EndOfDocument);
foo.SelectedTextRange = allRange;
But nothing happens; foo.SelectedTextRange remains unchanged and no text is highlighted. I made sure that that the field was already the first responder, in case that had an impact. I then tried simply moving the cursor by getting a text range with identical start and ending positions, and that also had no effect.
Inspection of "allRange" shows that it's getting correct start and end positions.
Am I missing something?
The SelectedText range does work as expected. I have attached a project that shows it. Nevertheless, can you please le me know in what thread are you doing the selection?
Created attachment 20735 [details]
This project will select the text in the input when the button is clicked.
Created attachment 20776 [details]
Sample View Controller
Ah ha, turns out my issue is that I'm trying to do the highlighting in EditingDidBegin for the text field. Attached a sample view controller.
Is this unsupported?
(Also, in answer to your earlier question, I tried forcing it on the main thread even though it should have already been there due to it being fired on a text field event handler, no luck).
I should point out that in this sample, you can successfully highlight with the button whenever the text field is the first responder, otherwise you have null beginning/ends of document. When trying to highlight within the EditingDidBegin handler by simply touching the textfield after you've filled in some text and hit Return, the beginning/end values are valid, but highlighting produces no result.
It seems there is no bug in the Xamarin iOS product itself and your question seems more related to API usage.
The broader developer community would be the best and quickest place for additional troubleshooting help on this issue.
Posting a question on Stack Overflow  or the Xamarin Forums  would be the best next step.
(Investigation by the Xamarin team in the bug tracker for an issue like this would usually require that the reporter includes additional background info to hint that Xamarin is behaving differently compared to Xcode.)
In case it might also be a helpful reference, you can find some general recommendations on the best places to ask various kinds of questions about Xamarin on: