微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在使用 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.

原文地址:https://www.jb51.cc/iOS/330166.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐