【问题标题】:Could not find keyboard scene delegate for interaction view找不到交互视图的键盘场景委托
【发布时间】:2021-08-07 08:11:41
【问题描述】:

在 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 }
    }

在我的实际应用程序中 - 如果用户是新用户(即我需要能够更改起始视图控制器),我会使用此子例程启动教程

【问题讨论】:

    标签: swift uitextfield uiscenedelegate ios15


    【解决方案1】:

    您的 SceneDelegate 函数 scene() 中似乎有问题。

    试试这个我从手头的另一个项目中获取的代码。

        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()
        }
    

    【讨论】:

      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      • 2018-04-05
      • 2018-03-02
      • 2015-12-13
      相关资源
      最近更新 更多