简体   繁体   English

解雇键盘后如何恢复UIInputViewController self.view?

[英]How to restore UIInputViewController self.view after dismissing the keyboard?

I'm developing an application that has an Keyboard extension, At some uses of the Keyboard extension (for example: when I use the switch keyboard button) the extension is going through the viewDidDisappear and at this case I know I can clean the keyboard and it's getting deallocated with all it's views and the memory is freed. 我正在开发一个具有键盘扩展的应用程序,在键盘扩展的一些用途(例如:当我使用开关键盘按钮时)扩展名正在通过viewDidDisappear ,在这种情况下,我知道我可以清理键盘和它被取消分配所有的视图并释放内存。 At other uses (for example: when using the Notes application and pressing the Done/Back button) the extension is going through the viewWillDisappear but not through the viewDidDisappear , So in this case I'm not cleaning the Keyboard as it's not reaching my cleaning methods and therefore it's not getting deallocated. 在其他用途​​(例如:使用Notes应用程序并按下完成/返回按钮)时,扩展程序将通过viewWillDisappear,但不会通过viewDidDisappear ,所以在这种情况下,我没有清理键盘,因为它没有到达我的清洁方法,因此它没有被解除分配。

At this point I would expect that when I return to the keyboard by going back to the note for example I would receive the previous UIInputViewController with the view I already built. 在这一点上,我希望当我回到键盘回到例如笔记时,我会收到以前的UIInputViewController和我已经构建的视图。

Unfortunately at this point the isViewLoaded() method returns false and my UIInputViewController is going again through the loadView method therefore building again all the views all over again, as a result the application memory grows until at some point I reach the nasty didReceiveMemoryWarning method callback. 不幸的是,此时isViewLoaded()方法返回false ,我的UIInputViewController再次通过loadView方法,因此再次构建所有视图,结果应用程序内存增长,直到某些时候我到达讨厌的didReceiveMemoryWarning方法回调。

I would like to restore somehow the view I created for my keyboard in the UIInputViewController that was initialized first. 我想以某种方式恢复我在首先初始化的UIInputViewController中为我的键盘创建的视图。 Does some one know is it possible and how could this be achieved? 有人知道这是否可能,如何实现?

I was looking into the restorationIdentifier to accomplish this task, correct me if I'm wrong but this is used with an ordinary UIViewController and can't be used with the UIInputViewController as not my AppDelegate is responsible to launch it. 我一直在寻找进入restorationIdentifier来完成这个任务,纠正我,如果我错了,但是这是使用普通的UIViewController,不能与UIInputViewController作为不是我的AppDelegate负责启动它。

Update 更新

From further research I made, I came to a conclusion that no matter what the operation you commit: 根据我的进一步研究,无论你做了什么操作,我都得出结论:

  1. Use Done/Back button in the Notes application. 使用Notes应用程序中的“完成/返回”按钮。
  2. Switch to the Messages app and use the keyboard there. 切换到消息应用程序并在那里使用键盘。
  3. Use the “switch keyboard" button 使用“切换键盘”按钮

And other scenarios, the UIInputViewController class always goes through the init method . 在其他场景中, UIInputViewController类总是通过init方法

From my understanding of the object oriented programming this mean that whoever calls my keyboard to reaper does it using the constructor and basically creates a new instance of the keyboard. 根据我对面向对象编程的理解,这意味着无论谁将我的键盘调用到收割机,都会使用构造函数来创建一个新的键盘实例。 That means that I will never have an available view on first reappearance of the keyboard in any of the behaviors and I always have to build the keyboard view for the new instance and cleanup the old one. 这意味着我将永远不会在任何行为中首次重新出现键盘的可用视图,我总是必须为新实例构建键盘视图并清理旧实例。 Is this right? 这是正确的吗? or there is a way to presereve the view of the UIInputViewController? 或者有一种方法来预先检查UIInputViewController的视图?

Unless you're using your own custom application with the keyboard to store its previous instance, there's no way to do this. 除非您使用自己的自定义应用程序与键盘存储其先前的实例,否则无法执行此操作。 In everything besides a custom application designed by you, it is beyond your scope 除了由您设计的自定义应用程序之外的所有内容,它都超出了您的范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM