ios – 如何正确删除SFSafariViewController作为子视图控制器?

ios – 如何正确删除SFSafariViewController作为子视图控制器?,第1张

概述我正在使用 this SO answer提供的技术在SFSafariViewController中预加载一些URL,如下所示: addChildViewController(svc)svc.didMoveToParentViewController(self)view.addSubview(svc.view) 并且我尝试删除Safari View控制器与以下代码: svc.willMoveTo 我正在使用 this SO answer提供的技术在SFSafariVIEwController中预加载一些URL,如下所示:
addChildVIEwController(svc)svc.dIDMovetoParentVIEwController(self)vIEw.addSubvIEw(svc.vIEw)

并且我尝试删除Safari VIEw控制器与以下代码:

svc.willMovetoParentVIEwController(nil)svc.vIEw.removeFromSupervIEw()svc.removeFromParentVIEwController()

现在我可以预加载URL并显示Safari视图没有问题.然而,在我重复这个过程(预加载/显示/删除)几次(大概30次)后,应用程序将因为某些内存问题而崩溃,因为日志显示内存级别不正常或者该应用程序在应用程序被jetsam杀死崩溃.

在崩溃之前,我看到一些关于可能的泄漏警告的日志:

<Warning>: notify name "UIKeyboardSpringBoardKeyboardShow" has been registered 20 times - this may be a leak<Warning>: notify name "com.apple.SafariVIEwService-com.apple.uikit.vIEwService.connectionRequest" has been registered 20 times - this may be a leak

删除Safari VIEw控制器时是否正确进行?我错过了什么吗?还是解决这个问题的任何建议?

解决方法 如果您添加子视图控制器代码如上所述,那么我认为它的顺序应该与文档有所不同.
addChildVIEwController(svc)vIEw.addSubvIEw(svc.vIEw)svc.dIDMovetoParentVIEwController(self)

您应该首先添加子视图,然后调用dIDMovetoParentVIEwController.尝试这个,看看它是否有效.

Listing 5-1Adding a child vIEw controller to a container

(voID) displayContentController: (UIVIEwController*) content { [self addChildVIEwController:content]; content.vIEw.frame = [self
frameForContentController]; [self.vIEw
addSubvIEw:self.currentClIEntVIEw]; [content
dIDMovetoParentVIEwController:self]; }

In the preceding example,notice that you call only the
dIDMovetoParentVIEwController: method of the child. That is because
the addChildVIEwController: method calls the child’s
willMovetoParentVIEwController: method for you. The reason that you must call the dIDMovetoParentVIEwController: method yourself is that the method cannot be called until after you embed the child’s vIEw into your container’s vIEw hIErarchy.

总结

以上是内存溢出为你收集整理的ios – 如何正确删除SFSafariViewController作为子视图控制器?全部内容,希望文章能够帮你解决ios – 如何正确删除SFSafariViewController作为子视图控制器?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1097409.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存