相关疑难解决方法(0)

在内存警告(Apple doc flaw)中卸载iOS 6中的视图的正确方法是什么?

在iOS 6中,viewWillUnloadviewDidUnload已被取消,UIViewControllers不再卸载观点,即内存警告时不显示在屏幕上.该视图控制器编程指南对如何手动还原此行为的一个例子.

这是代码示例:

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Add code to clean up any of your own resources that are no longer necessary.
    if ([self.view window] == nil)
    {
        // Add code to preserve data stored in the views that might be
        // needed later.

        // Add code to clean up other strong references to the view in
        // the view hierarchy.
        self.view = nil;
    }
}
Run Code Online (Sandbox Code Playgroud)

代码示例下面是以下注释:

下次访问视图属性时,视图将与第一次完全重新加载.

这里有一个明显的缺陷.如果未加载其视图的视图控制器收到内存警告,它将在该行中加载其视图if ([self.view window] …

uiviewcontroller didreceivememorywarning ios6

11
推荐指数
1
解决办法
1万
查看次数