删除scrollview中的子视图控制器

时间:2014-08-13 00:40:38

标签: ios xcode scrollview

我有UIScrollView(已启用分页),其中包含4个UIViewControllers。我注意到每当我导航/滚动到那些视图控制器时,内存逐渐增加。我知道如果未显示控制器,我必须删除UIViewControllers内的子视图UIScrollView,但我不知道该怎么做。

有人可以分享他们关于如何移除未使用的UIViewControllers的想法,并将其重新放回UIScrollView

这是我在滚动视图中添加子视图的代码。

controllers = [[NSMutableArray alloc] initWithCapacity:0];

first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
first.view.tag = 0;
[scrollView addSubview:first.view];
first.view.frame = CGRectMake(0,0, 768, 919) ;
[controllers addObject:first];

second = [self.storyboard instantiateViewControllerWithIdentifier:@"Second"];
second.view.tag = 1;
[scrollView addSubview:second.view];
second.view.frame = CGRectMake(768 , 0, 768, 919) ;
[controllers addObject:second];

third = [self.storyboard instantiateViewControllerWithIdentifier:@"Third"];
third.view.tag = 2;
[scrollView addSubview:third.view];
third.view.frame = CGRectMake(768 + 768, 0, 768, 919) ;
[controllers addObject:third];

fourth = [self.storyboard instantiateViewControllerWithIdentifier:@"Fourth"];
fourth.view.tag = 3;
[scrollView addSubview:fourth.view];
fourth.view.frame = CGRectMake(768 + 768 + 768, 0, 768, 919) ;
[controllers addObject:fourth];

感谢。

0 个答案:

没有答案