簡體   English   中英

如何從 UIScrollView 中卸載 UIViewController?

[英]How do I unload a UIViewController from a UIScrollView?

我使用幾乎相同的代碼將我的 UIViewController(稱為 LessonScrollView)加載到 UIScrollView 中。 在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];
}

}

在某些情況下,我相信有相當多的頁面保留在 memory 中,直到負責滾動視圖的 UIViewController 被釋放(或出現 memory 警告)。

我的問題是,我將如何發布 LessonScrollView object。 我會調用一個方法,比如說

- (void)unloadScrollViewWithPage:(int)page 

在 scrollViewDidScroll 和 page 將是當前頁面 - 1。

謝謝你盡你所能的幫助。

嘗試這個:

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM