3

I'm trying to implement my own UITextInput however I'm having trouble updating the position using the cursor key on a Bluetooth keyboard. I'm trying to create a TextInput that loops, if you imagine the characters being numbered like this:

1 2 3
4 5 6
7 8 9

Then pressing up at position 2, should take you to position 8 (pressing left on 6 takes you to 4 etc). iOS seems to call positionFromPosition:inDirection:offset: to figure how where to move from the current position. It then calls setSelectedTextRange: to update the cursor position.

This is fine so far, but it seem that sometimes iOS DOESN'T call positionFromPosition:inDirection:offset: for example if I press Up and then Down again, iOS appears to cache the previous position and just call setSelectedTextRange: with that previous value. I don't understand this, is there a way of telling iOS that the selected position has changed and it should clear it's cache, i.e. if someone presses a "clear" button or something?

The caching ONLY seems to occur for Up and Down cursor key presses, moving left and right never caches previous values and positionFromPosition:inDirection:offset: is always called. Even if I don't consider the possibility of something reseting the cursor position I still have issues with "positionFromPosition:inDirection:offset:" not being called occasionally, and I just keep getting "setSelectedTextRange:" set to the same value by iOS. So if feels like there's something I've misunderstood about how iOS is caching cursor movement. Can anyone help me out?

new299
  • 804
  • 1
  • 7
  • 17
  • I guess that I don't understand the problem here. If you press up, and then down (quickly enough to where it caches it), shouldn't you end up back at the same location? They would "cancel each other out" in this case.... – lnafziger Feb 17 '13 at 18:11
  • @lnafziger what if something else changed the cursor position in the mean time? Like a clear button or similar? How would I tell iOS about this? – new299 Feb 18 '13 at 03:06
  • @lnafziger I'm also finding it sometimes just jams up and the same position keeps being sent to setSelectedTextRange: which makes me think there's something I'm missing. – new299 Feb 18 '13 at 03:10
  • @lnafziger one other point is that it's not time dependant so "quickly enough to where it caches it" doesn't apply. It always caches and is only cleared when I move left/right. – new299 Feb 18 '13 at 03:14
  • Does it do the same thing if you use an actual `UITextView` instead of your custom class? I.e. does the position keep getting sent, etc? – lnafziger Feb 18 '13 at 03:47
  • Is your interaction between your keyboard and your custom class happening on the main thread? Remember, all UIKit interaction must happen on the main thread or "strange" things happen... – lnafziger Feb 18 '13 at 03:48
  • @lnafziger yes it is. – new299 Feb 25 '13 at 21:19
  • @new299 did you ever resolve this issue? I am creating my own uitextinput and would be interested in hearing what you found. Thanks. – R.S Oct 09 '13 at 06:29
  • @R.S no I /don't think/ I ever found a clear way round the issue, but I forget exactly what hacks I put in place. But you can check the sourcecode to hterm to which this question refers here: https://github.com/new299/hackterm my hacks are in the SDL2 library I include. – new299 Oct 10 '13 at 00:01

0 Answers0