Hi,
I'm trying to create a UITextView where, along with the keyboard, users could press buttons to insert text.
My first problem was that the view would always place the text selection cursor to the end of the text and then scroll all the way down.
I was able to fix this by keeping a record of the current selectionRange then using setSelectionRange to restore the previous state.
However, there is still a problem where it acts like all the text is deleted and then replaced. This causes it to scroll up then back down to where the selectionRange is located. In effect, it bounces around whenever the text is modified.
Is there any way to prevent this?
Obviously the iPhoneOS keyboard is perfectly capable of this, are whatever tools it uses to do that available to us?
I'm trying to create a UITextView where, along with the keyboard, users could press buttons to insert text.
My first problem was that the view would always place the text selection cursor to the end of the text and then scroll all the way down.
I was able to fix this by keeping a record of the current selectionRange then using setSelectionRange to restore the previous state.
However, there is still a problem where it acts like all the text is deleted and then replaced. This causes it to scroll up then back down to where the selectionRange is located. In effect, it bounces around whenever the text is modified.
Is there any way to prevent this?
Obviously the iPhoneOS keyboard is perfectly capable of this, are whatever tools it uses to do that available to us?
Code:
-(void)addText:(string)in backIndex:(NSInteger)bi
{
string current = [editorTextView.text UTF8String]; //keep record of current text
NSRange selectionRange = editorTextView.selectedRange; // '' current selection
current.insert(selectionRange.location, in); //insert new text
selectionRange.location += in.length() - bi; //adjust selection accordingly
[editorTextView setText:[NSString stringWithUTF8String:current.c_str()]]; //apply the new text
[editorTextView setSelectedRange:selectionRange]; //apply the new selection
}