Change cursor in UITextField when set new text

旧城冷巷雨未停 提交于 2019-12-04 07:25:11

I found the solution. I can't choice the cursor place, but it do what I want. You have to use the function of protocol UIKeyInput There are 2 good function:

- (void)insertText:(NSString *)text;
- (void)deleteBackward;

Than, redoing my test case, I have:

"|"      => Empty , type a
"a|"     => type b               (put character "-" automatic)
"a-b|"   => user change cursor
"a|-b"   => type c               (enter the character with a [textField insertText:@"c"]
"ac|-b"  => type d               (the same thing: [textField insertText:@"d"])
"acd|-b" => change cursor
"ac|d-b" => type backspace       (use a [textField deleteBackward])
"a|d-b"  => type backspace
"|d-b"   => *result*             (Work!!!)

You can't change the cursor, but for normal typing it solve the problems!.

Did you try using the UITextInput protocol for gathering cursor position information?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!