我有一个带有4个按钮和一个容器视图的View控制器。当我点击4个不同的按钮时,应该出现在容器视图中的另外4个视图控制器。但是,当我继续点击不同的按钮时,应用程序崩溃了。记忆没有解除分配。
-(void)viewDidDisappear:(BOOL)animated{
self.view=nil;
}
这段代码用于解除分配视图。但它仍在消耗内存。当视图不在容器视图上时,有没有办法解除分配视图? 我的容器类有4个按钮和一个容器,代码如下所示:
- (IBAction)view1:(id)sender {
pinkViewController *pink = [self.storyboard instantiateViewControllerWithIdentifier:@"pink"];
[self.containerView addSubview:pink.view];
}
- (IBAction)view2:(id)sender {
redViewController *red = [self.storyboard instantiateViewControllerWithIdentifier:@"red"];
[self.containerView addSubview:red.view];
}
- (IBAction)view3:(id)sender {
orangeViewController *orange = [self.storyboard instantiateViewControllerWithIdentifier:@"orange"];
[self.containerView addSubview:orange.view];
}
- (IBAction)view4:(id)sender {
greenViewController *green = [self.storyboard instantiateViewControllerWithIdentifier:@"green"];
[self.containerView addSubview:green.view];
}