UITextField将不间断的空格转换为空格?

编程入门 行业动态 更新时间:2024-10-28 04:22:53
本文介绍了UITextField将不间断的空格转换为空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

看来,UITextFields会转换所有不间断空格(nbsp,U + 00A0 )到空格(U + 0020)。这会导致编辑区域设置特定数字时出现问题。例如,在法语/法语区域中,不间断空格分隔1和%形成1%。但是,由于UITextField将分隔符字符转换为空格,因此区域设置感知NSNumberFormatter无法解析语言环境字符串并将其转换为数字。

It seems UITextFields convert all non-breaking spaces (nbsp, U+00A0) to spaces (U+0020). This causes problems for the editing of locale specific numbers. For instance, in the French/France locale, the non-breaking space separates 1 and % to form "1 %". However, since the UITextField converts the separator character to a space, the locale aware NSNumberFormatter is unable to parse the locale string and convert it to a number.

以下代码段说明这个问题。

The following code snippet illustrates this problem.

NSLocale *fr_FR = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease]; NSNumberFormatter *percentageFormatter = [[NSNumberFormatter alloc] init]; [percentageFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4]; [percentageFormatter setGeneratesDecimalNumbers:TRUE]; [percentageFormatter setNumberStyle:NSNumberFormatterPercentStyle]; [percentageFormatter setLocale:fr_FR]; NSDecimalNumber *one = [NSDecimalNumber decimalNumberWithString:@"0.01"]; // will be "1 %" where the separator character is a nbsp (this is correct) NSString *percentage = [percentageFormatter stringFromNumber:one]; UITextField *textField = [[UITextField alloc] init]; textField.text = percentage; // will be "1 %" where the separator character is a space (this is wrong) NSString *textFieldValue = textField2.text; // returns an indeterminate value: may throw an exception, may return nil, etc // this should return the number 0.01 NSNumber *percentageNumber = [percentageFormatter numberFromString:textFieldValue];

我的问题:如何防止UITextField将不间断的空格转换为空格?

My question: How do I prevent the UITextField from converting non-breaking spaces to spaces?

我了解我可以使用的工作,如果我在一个使用不间断空格的区域设置,它可以工作。但是,如果有UITextField的属性/行为,我不知道要保留,我想知道。

I understand the work arounds I can employ to hack this so that it works if I'm in a locale that uses non-breaking spaces. However, if there is property/behavior of the UITextField that I'm not aware of to preserve nbsp, I'd like to know.

推荐答案

我很确定这个功能不存在。如何为iPhone打开错误报告?

I'm pretty sure this feature doesn't exist. How about opening a bug report for the iPhone?

更多推荐

UITextField将不间断的空格转换为空格?

本文发布于:2023-10-05 08:54:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1467339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   将不   转换为   UITextField

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!