iPhone SDK:禁用在文本字段(或文本视图)中自动创建点 (.) [英] iPhone SDK: disable auto creation of dot (.) in text field (or textview)
问题描述
我已禁用文本字段的自动更正类型,并且它不显示任何其他自动更正,
I've disabled auto-correction type for my text field, and it does not show any other auto-correction,
但是当我按两次空格键时它仍然会自动创建一个点 (.).
but it still automatically creates a dot (.) when I press space key twice.
例如,如果我写测试"并按两次空格键,它会自动变为测试".
For example, if I write "test" and press space key twice, it automatically changes into "test. "
有人知道如何禁用此功能吗?
Anyone knows how to disable this feature?
非常感谢.
推荐答案
我找到了一个解决方案 - 它使用 UITextFieldTextDidChangeNotification 因为这是在应用自动更正后发生的.
I found one solution - it uses UITextFieldTextDidChangeNotification because this occurs after the auto-correction applies.
- 为文本字段设置代理
设置通知
- Set the delegate for the text field
Set up a notification
- (void) viewDidLoad {
...
[[NSNotificationCenter defaultCenter] addObserver:self
选择器:@selector(textFieldDidChange:)
名称:UITextFieldTextDidChangeNotification 对象:tfTitle];
}
然后,通知处理程序- (void)textFieldDidChange:(NSNotification *)aNotification
{
if ( [textField.text rangeOfString:@"."].length ) {
//更改文本
textField.text = [textField.text stringByReplacingOccurrencesOfString:@"." withString:@" "];
}
}
这篇关于iPhone SDK:禁用在文本字段(或文本视图)中自动创建点 (.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!