Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-07-2011, 03:04 PM   #1 (permalink)
svs
Registered Member
 
Join Date: Dec 2011
Posts: 2
svs is on a distinguished road
Default 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.
Attached Files
File Type: zip UITextViewTest.zip (58.8 KB, 3 views)
svs is offline   Reply With Quote
Old 02-28-2012, 06:29 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 22
xarel is on a distinguished road
Default

Hey, I stumbled upon the same problem today, have you found any solutions?

I suspect this is some built-in formatting feature of UITextview, similar to the automatic insertion of new lines.
The rule seems to be:
Spaces are drawn between other characters, but not if there is no other character on the same line.

It seems that the spaces do appear in the resulting textview.text string though, so I am thinking of replacing the last space with an invisible unicode sign, perhaps that would cause the spaces to be drawn?

I'd gladly appreciate any further hints you might have...

Thanks, x
xarel is offline   Reply With Quote
Reply

Bookmarks

Tags
end line, space, text view, uitextview, wrap

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 411
13 members and 398 guests
7twenty7, AppsBlogger, David-T, Duncan C, EvilElf, HemiMG, heshiming, iekei, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0