菜鸟教程小白 发表于 2022-12-12 21:09:56

ios - 禁用硬件键盘编辑 UITextField


                                            <p><p>我有一个 <code>UITextField</code>,点击它时会显示一个 <code>UIPickerView</code> (<code>_myTextField.inputView = _myPicker;</code>)。</p>

<p>但是,在模拟器中,我可以使用我的 Mac 键盘输入 <code>UITextField</code>。这是不可取的,因为我正在使用 <code>UIPickerView</code>。</p>

<p>如何禁用或忽略使用选择器的文本字段的硬件键盘输入?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以使用 <code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string</code> 来拒绝任何具有单个字符输入的内容(例如键按,我相信它的 <code>range.length</code> 为 1)。这对复制/粘贴操作没有帮助,但会涵盖单次击键。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 禁用硬件键盘编辑 UITextField,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/22770188/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/22770188/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 禁用硬件键盘编辑 UITextField