0

我创建了一个视图控制器,其中包含以下代码viewDidLoad

[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View1"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View2"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View3"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View4"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View5"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View6"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View7"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View8"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View9"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View10"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View11"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View12"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View13"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"View14"]];

当我打开一个新的 ViewController 并使用以下代码返回到初始 ViewController 时:

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Home"];
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:vc animated:YES completion:NULL];

我收到内存警告。

4

1 回答 1

2

您不会返回那里的主视图控制器,而是创建主控制器的新实例并呈现它。这样做的次数足够多,你最终会遇到大量控制器和内存不足的情况。

尝试解散您的控制器,尽管从您的问题中并不清楚您是如何到达包含所有子控制器的 VC 的。

于 2013-03-20T11:30:10.203 回答