开发者

Can't append space at end of UITextView

开发者 https://www.devze.com 2023-01-01 03:13 出处:网络
I have a UITextView in which I want the initial value to be \"@username \" when they keyboard shows up (notice the space after the username). This way the user can start typing right away without havi

I have a UITextView in which I want the initial value to be "@username " when they keyboard shows up (notice the space after the username). This way the user can start typing right away without having to tap space. So I do:

textView.text = [NSString stringWithFormat:@"@%@ ", username];

But it seems like it's impossible to have the UITextView text property ending with a space (it always gets stripped out). Am I correct? Is there any worka开发者_JS百科round for this?

I tried using the \s char and no success.

EDIT: see first answer below. Bug has been submitted to Apple — #8038616


I can find similar questions to yours using Google (i.e. http://www.iphonedevsdk.com/forum/iphone-sdk-development/44039-uitextview-whitespace-cursor-position.html) so I'm actually inclined to think this might be a bug with UITextView, where it's trimming whitespace in its text setter method. I'd suggest filing a bug.

Edit: this only seems to happen when the UITextView is not in editing mode. When in editing mode with the keyboard raised, you can set text, like Twitterific. However, the trimming behaviour present, when the UITextView is not in editing mode, is a bug -- please report it so it can get fixed (and let us know the # if you do).


NSString does not strip whitespace unless you ask it to. If there is no space in the UI, something else is stripping the spaces.


I tested this through an NSLog statement and could not replicate your symptom:

NSLog(@"@%@ ", @"test");

While the whitespace is not directly visible, it can be made visible by highlighting text in the console.

It is likely your problem is somewhere else.

0

精彩评论

暂无评论...
验证码 换一张
取 消