ios 模式到以前的 View Controller 会产生内存问题

标签 ios memory-leaks uistoryboardsegue

我的 View 系统非常糟糕。我浏览了几个模态视图,然后想跳回原来的 View (自身循环)。唯一的问题是,它会不断在其他 View 之上分配新 View ,直到我耗尽内存并且应用程序崩溃。如何告诉我的应用程序我永远不会回到预览 View Controller 并且它应该释放内存块?我想做这样的事情: self.presentingViewController = nil; 但它是只读的,我越想越觉得它不能那样工作。 这是我的 Storyboard。 enter image description here

最佳答案

尚不完全清楚您在做什么以及为什么它不能按您的预期工作,但我认为以下方法应该适合您:

  1. 我从“根 TableView ”开始,然后执行模态

  2. *然后从带有“占位”文本的 View 中我模态到游戏 Controller

  3. 然后我想模态回到导航 Controller /根 TableView 。

我假设您正在使用 –presentViewController:animated:completion: (或现已弃用的 –presentModalViewController:animated:)执行 1. 和 2。

为了执行 3.,您必须调用:

[self.presentingController DismissViewControllerAnimated:ZZZ 完成:nil];

这将关闭从根 TableView 到您要关闭的所有模态视图 Controller 。

如果您已经这样做了,但它没有按您想要的方式工作,我认为这可能是因为您正在忽略模态视图 Controller 并在同一运行循环周期内呈现一个新的 View Controller 。要解决这个问题,只需在根 Controller 中定义一个方法,例如:

    - (void)presentFirstViewController {
        [self presentViewController:xxxxx animated:YES completion:nil];
    }

稍后您关闭模态 Controller 执行以下操作:

self.presenting.Controller dismissViewControllerAnimated:YES completion:nil];

并展示新人正在做的事情:

[rootController performSelector:@selector(presentFirstViewController) withObject:nil afterDelay:0.0];

最后一步将为运行循环提供一些时间来在关闭时清理内容,并连续呈现模态 Controller 。

希望这有帮助。

关于ios 模式到以前的 View Controller 会产生内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14019789/

相关文章:

c# - .NET 4.5 Async + Await Fire and Forget 潜在的内存泄漏?

iphone - 有谁知道如何解决从 UIModalTransitionStylePartialCurl segue 退出时未触发 viewDidAppear 的问题?

ios - 以点值检测 iPhone 6/6+ 屏幕尺寸

从后台打开应用程序时,iOS swift 3 重新加载 tableview

ios - 组 TableView 背景颜色在 ios 6.0 中已弃用

ios - 条件绑定(bind)的初始化程序必须具有可选类型,而不是 '(CLLocationCoordinate2D, String, UIColor) -> UIView' ?

internet-explorer - 如何在 IE 中运行的 Web 应用程序中查找内存泄漏?

c++ - 这是内存泄漏吗?试图重置类型类的类成员。 C++

ios - 在 Swift 中的 TableView 和另一个 ViewController 之间传递数据

ios - 未触发 Unwind segue