UITextView Does Not Receive Spaces
In my project it is necessary to capture any spaces that are entered into a UITextView. I need to distinguish between a single space and a double space.
Under certain circumstances, the UITextView does not receive additional spaces. This happens when the cursor is at the end of the line, at the end of the text, before the text wraps to the next line. Spaces that are entered are not displayed and only sometimes counted.
I have a sample project that demonstrates this. Load the app in the simulator and press the space character to enter spaces into the UITextView. The number of characters will be displayed in a label. Once the cursor reaches the wrapping point, the characters are not entered and NOT COUNTED, these characters are gone.
Strange observation: Use the backspace to delete the spaces and one ".". Add spaces to reach the wrapping point and now the spaces are counted as would be expected. Repeat the process, removing another "." and it will not work, remove another and it does.
In other circumstances it is possible to add as long a sequence of spaces as desired. For example if the cursor is not near the end of the line.
I have managed to create a workaround by keeping track of whether spaces were effectively entered or not and adding them the next time a non-space character is added, but this is dirty and I don't feel I should have to do this.
Same result on simulator, as well as devices running iOS ranging from iOS 3 to 5. It doesn't matter if the characters are being entered by keyboard or dynamically with NSString replaceCharactersInRange.
Is there something simple I am missing? I found nothing online about such issues or bug reports. I don't want to manage spaces being entered into a UITextView. I would prefer it just wrap spaces in this case.
Thanks.
|