当我运行模拟器并在UITextView中单击时,键盘不会显示。如何重新启用键盘?

它曾经有效,但现在不行了——我不知道我可能偶然点击了什么。


当前回答

如果模拟器中没有自动显示键盘,只需按[Command+K]

或硬件->键盘->切换软件键盘

其他回答

这对我有用。单击I/O,然后单击键盘。当取消选择“连接硬件键盘”时,模拟器键盘将弹出。

要启用/禁用模拟器键盘:单击⇧+⌘+K在模拟器上显示键盘,再次单击以禁用(隐藏)键盘。

⇧+⌘+K

OR

模拟器->I/O->键盘->切换软件键盘

使用脚本您可以通过Xcode预运行操作运行

/usr/libexec/PlistBuddy -c "Print :DevicePreferences" 
~/Library/Preferences/com.apple.iphonesimulator.plist | perl -lne 'print 
$1 if /^    (\S*) =/' | while read -r a; do /usr/libexec/PlistBuddy -c 
"Set :DevicePreferences:$a:ConnectHardwareKeyboard false" 
~/Library/Preferences/com.apple.iphonesimulator.plist || /usr/libexec/PlistBuddy -c  "Add :DevicePreferences:$a:ConnectHardwareKeyboard bool false" ~/Library/Preferences/com.apple.iphonesimulator.plist; done

如果模拟器的键盘未通过按K键打开,则将模拟器重置为出厂设置。转到模拟器菜单设备->擦除所有内容和设置。。它将解决键盘无法打开的问题。

在viewDidLoad中添加此行

yourUiTextField.becomeFirstResponder()