我的 View 系统非常糟糕。我浏览了几个模态视图,然后想跳回原来的 View (自身循环)。唯一的问题是,它会不断在其他 View 之上分配新 View ,直到我耗尽内存并且应用程序崩溃。如何告诉我的应用程序我永远不会回到预览 View Controller 并且它应该释放内存块?我想做这样的事情: self.presentingViewController = nil; 但它是只读的,我越想越觉得它不能那样工作。 这是我的 Storyboard。
最佳答案
尚不完全清楚您在做什么以及为什么它不能按您的预期工作,但我认为以下方法应该适合您:
我从“根 TableView ”开始,然后执行模态
*然后从带有“占位”文本的 View 中我模态到游戏 Controller
然后我想模态回到导航 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/