xcode 在 iOS 上以编程方式更改键盘类型没有任何作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12619375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:40:10  来源:igfitidea点击:

Programmatically changing keyboard type on iOS does nothing

objective-ciosxcodeuikeyboardtype

提问by Kladimir

I want to change keyboard type from default to numeric after user pressed return button. However after setting keyboardType property nothing happens.

我想在用户按下返回按钮后将键盘类型从默认更改为数字。但是在设置 keyboardType 属性后什么也没有发生。

My code:

我的代码:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

    return YES;
}

I have set myself as text field delegate and the method is being called after pressing return button.

我已将自己设置为文本字段委托,并在按下返回按钮后调用该方法。

EDIT: Solved by

编辑:解决

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
    [textField reloadInputViews];
    return YES;
}

回答by pro_metedor

Try this:

尝试这个:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
    [textField reloadInputViews];
    return YES;
}

回答by Muhammad Zaheer

You can do this in the Text Input Traits section under the Attributes inspector.

您可以在属性检查器下的文本输入特征部分执行此操作。