UITextField setAutocapitalizationType 奇怪的行为
我有两个 XIB 生成的 UITextFields,我在 -viewWillAppear: 中有条件地配置它们,如下所示:
//Configure text fields
[emailField setDelegate:self];
[emailField setKeyboardType:UIKeyboardTypeEmailAddress];
[emailField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[emailField setAutocorrectionType:UITextAutocorrectionTypeNo];
[nameField setDelegate:self];
[nameField setKeyboardType:UIKeyboardTypeAlphabet];
[nameField setAutocapitalizationType:UITextAutocapitalizationTypeWords];
[nameField setAutocorrectionType:UITextAutocorrectionTypeNo];
emailField 行为正常。 nameField 表现正常,但有一个例外:
当 nameField 成为第一响应者时,通过调用 -becomeFirstResponder 或点击该字段,Shift/Caps 按钮会突出显示(如预期),并针对后续字符关闭(如预期),但没有字符实际上都是大写的。
I've got two XIB-generated UITextFields that I'm conditionally configuring in -viewWillAppear: as follows:
//Configure text fields
[emailField setDelegate:self];
[emailField setKeyboardType:UIKeyboardTypeEmailAddress];
[emailField setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[emailField setAutocorrectionType:UITextAutocorrectionTypeNo];
[nameField setDelegate:self];
[nameField setKeyboardType:UIKeyboardTypeAlphabet];
[nameField setAutocapitalizationType:UITextAutocapitalizationTypeWords];
[nameField setAutocorrectionType:UITextAutocorrectionTypeNo];
emailField behaves normally. nameField behaves normally with one exception:
When nameField becomes the First Responder, either by calling -becomeFirstResponder or by tapping in the field, the Shift/Caps button highlights (as expected), and turns off for subsequent characters (as expected), but no characters are ever actually capitalized.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
酷,我是个白痴。
此行为发生在模拟器中,我正在使用 Mac 键盘输入文本。当然,它不会资本化。
单击模拟器中的键盘按键会产生正确的结果,就像在设备上运行应用程序一样。
希望其他人可以解决这个问题。
(:麦基:)
Cool, I was being an idiot.
This behavior was taking place in the simulator, and I was using my Mac's keyboard to enter the text. Of course it wasn't going to capitalize.
Clicking on the keyboard keys in the simulator produced proper results, as did running the app on-device.
Hope someone else can save a headache with this.
(:Mikey:)