简体   繁体   English

如何从 UIScrollView 中卸载 UIViewController?

[英]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.

相关问题 如何在Swift中将UIViewController添加到UIScrollView - How Do I Add UIViewController to UIScrollView in Swift 如何将touchesBegin从UIScrollView传递到UIViewController - how to pass touchesBegan from UIScrollView to UIViewController 如何从UIViewController中删除UINavigationBar? - How do I remove the UINavigationBar from a UIViewController? 如何获取从标准 UIViewController 中调用的 UIWebView 的 UIScrollView 委托方法? - How can I get a UIWebView's UIScrollView delegate methods called from within a standard UIViewController? 如果我在UIScrollView中有一个UIViewController,如何以编程方式使UIScrollview zoomToRect? - If I have a UIViewController in a UIScrollView how can I programmatically make the UIScrollview zoomToRect? 如何在注销操作中取消分配uiviewcontroller / unload视图 - How to dealloc uiviewcontroller/unload views on logout action 如何从UIViewController调用应用程序委托的方法? - How do I call a method of the app delegate from a UIViewController? 如何从UIView访问UIViewController的按钮? - How do I access a UIViewController's button from a UIView? 如何从 uiviewcontroller 加载 class 中的方法 - How do I load a method thats in a class from a uiviewcontroller 如何从带有占位符的NIB加载UIViewController? - How do I load a UIViewController from a NIB with placeholders?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM