UITextInput setMarkedText:selectedRange not working? (Can't be!)

Posted by nacho4d on Stack Overflow See other posts from Stack Overflow or by nacho4d
Published on 2011-11-09T14:41:19Z Indexed on 2011/11/20 1:51 UTC
Read the original article Hit count: 439

I want to set the marked text programmatically and since iOS5 UITextView and UITextField conform to UITextInput this should be possible but for some reason I always get the markedText to be nil. :( What am I missing here?

This is what I've tried without success:

(While the textview is firstResponder)

1.- When the text view contains no text:

text: "", selectedRange : {0,0}, markedText: nil.

[_textView setMarkedText:@"?" selectedRange:NSMakeRange(0, 1)];

Result: text : "", selectedRange: {0,0}, markedText: nil. (Nothing changed)


2.- When the text view contains text + some marked text:

text : "AAA", selectedRange = {0,3}, marked text at the end : "??" then I do:

[_textView setMarkedText:@"?" selectedRangeNSMakeRange(0,3)];

Result : text :"AAA", selectedRange: {0,3}, markedText: nil; (the marked text became nil)


In both cases is like setMarkedText:selectedRange: would be setting the current marked text (if some) to nil.

Any help would be highly appreciated :)

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c