[英]How do I unload a UIViewController from a UIScrollView?
I am using pretty much the same code to load my UIViewController (called LessonScrollView) into the UIScrollView.我使用几乎相同的代码将我的 UIViewController(称为 LessonScrollView)加载到 UIScrollView 中。 The method is called when in the scrollViewDidScroll method
在scrollViewDidScroll方法中调用该方法
- (void)loadScrollViewWithPage:(int)page {
if (page < 0)
return;
if (page >= numPages)
return;
LessonScrollView *controller = [imageViewControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
controller = [[LessonScrollView alloc] initWithPage:page forLesson:[self title]];
[imageViewControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
if (controller.view.superview == nil) {
CGRect frame = CGRectMake(0, 80, 320, 285);
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
} }
In some circumstances I have quite a few pages, which I believe, remain in memory until the UIViewController responsible for the scrollView is released (or a memory warning occurs).在某些情况下,我相信有相当多的页面保留在 memory 中,直到负责滚动视图的 UIViewController 被释放(或出现 memory 警告)。
My question is, how would I release the LessonScrollView object.我的问题是,我将如何发布 LessonScrollView object。 I would call a method called, say
我会调用一个方法,比如说
- (void)unloadScrollViewWithPage:(int)page
in scrollViewDidScroll and page would be the current page - 1.在 scrollViewDidScroll 和 page 将是当前页面 - 1。
Thanks for any help you can offer.谢谢你尽你所能的帮助。
Try this:尝试这个:
[controller.view removeFromSuperview];//to release the controller's view
[imageViewControllers replaceOjectAtIndex:page withObject:[NSNull null]];//to release the actual controller which should lead to it being dealocated
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.