swift - 找不到交互视图的键盘场景委托
问题描述
在 iOS 13 以下,我的 UITextField 正确启动键盘并让用户输入他们的答案。
在 iOS 13 以上,textFieldDidBeginEditing()
当我点击文本字段时触发,但未显示键盘,因此用户无法给出答案。
调试控制台不会立即抛出任何错误,但最终会出现以下消息,我认为这是关键:
Could not find keyboard scene delegate for interaction view
我认为该错误出现在后来的 iOS 中,因为场景成为主要内容 - 我需要在某个地方设置一个委托以允许键盘出现在第一个场景的正面。
不知道如何做到这一点!
我的 UITextField 是完全标准的。为了重现错误,我在 SceneDelegate 中有以下设置代码
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let windowScene = UIWindowScene(session: session, connectionOptions: connectionOptions)
self.window = UIWindow(windowScene: windowScene)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "VC" )
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
guard let _ = (scene as? UIWindowScene) else { return }
}
在我的实际应用程序中 - 如果用户是新用户,我使用此子例程启动教程(即我需要能够更改起始视图控制器)
解决方案
在您的 SceneDelegate 函数场景 () 中似乎有些问题。
试试我从手头的另一个项目中获取的这段代码。
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
self.window?.rootViewController = ViewController()
self.window?.makeKeyAndVisible()
}
推荐阅读
- c# - 如何确定一个值是由 NHibernate C# 还是由应用程序代码设置的?
- microservices - 事件溯源 - 事件流说明
- node.js - 如何将 webpack-dev-middleware 添加到现有节点/反应应用程序
- r - 如何在多个绘图的网格中将绘图调整为相同大小
- elasticsearch - Grok Pattern - 用于逗号分隔的数据
- amazon-web-services - 我可以使用不同区域中的节点 Lambda 更新另一个区域中的资源(如 Autoscalinggroup)吗?
- java - 如何实现流
在 Java 中没有资源泄漏警告 - r - 如何将权重纳入 WinBUGS 模型的可能性?
- html - 剪辑路径上的文本
- javascript - 有条件地设置来自 API 的数组值的样式