UIKeyInput 键盘类型协议要求不匹配。

问题描述 投票:0回答:1

我有一个 UIView 的子类,符合 UIKeyInput 协议。我想将键盘类型设置为 numberPad. 不幸的是,设置这个属性没有任何作用。

var keyboardType: UIKeyboardType {
    .numberPad
}

编译器用以下描述警告我。

Property 'keyboardType' nearly matches optional requirement 'keyboardType' of protocol 'UITextInputTraits'

因此,我知道这个属性并不是指... UIKeyInput 协议。我在寻找其他协议或类,叫做 UIKeyInput但我没有发现任何问题。

你有什么建议吗,还有什么原因会导致这个问题?

swift uikit protocols uikeyboardtype uikeyinput
1个回答
1
投票

作为 文件 显示你应该为这个属性提供getter和setter。

optional var keyboardType: UIKeyboardType { get set }
© www.soinside.com 2019 - 2024. All rights reserved.