我正在使用提供的技术这个答案 https://stackoverflow.com/a/35356986/830098在 SFSafariViewController 中预加载一些 URL,如下所示:
addChildViewController(svc)
svc.didMoveToParentViewController(self)
view.addSubview(svc.view)
我尝试使用以下代码删除 Safari View 控制器:
svc.willMoveToParentViewController(nil)
svc.view.removeFromSuperview()
svc.removeFromParentViewController()
现在我可以预加载 URL 并毫无问题地显示 Safari 视图。但是,在我多次重复该过程(预加载/显示/删除)后(可能超过 30 次),应用程序将由于某些内存问题而崩溃,因为日志显示Memory level is not normal or this app was killed by 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)
您应该首先添加子视图,然后调用 didMove ParentViewController。试试这个,看看是否有效。
清单 5-1 将子视图控制器添加到容器中
- (void) displayContentController: (UIViewController*) content { [self addChildViewController:content]; content.view.frame = [自身
frameForContentController]; [自我看法
addSubview:self.currentClientView]; [内容
didMoveToParentViewController:self]; }
在前面的示例中,请注意您仅调用了
didMoveToParentViewController:子级的方法。那是因为
addChildViewController: 方法调用子视图的
willMoveToParentViewController: 适合您的方法。原因是你
必须自己调用 didMoveToParentViewController: 方法是
在嵌入子视图之后才能调用该方法
进入容器的视图层次结构。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)