【发布时间】:2013-01-23 23:33:48
【问题描述】:
我制作了一个在滚动视图中包含图像视图的应用。
我有 3 个班级,每个班级都将图像添加到图像视图中。
当我按下按钮 1 时,它会调用 class1 并填充 Class1 图像(从 image001 到 image200)。
当我按下button2时,它会调用class2并填充Class2images(从image201到image400)
问题是当我调用 class1 时,图像视图显示 class1images(从 image001 到 image200)。
调用class1后,我调用class2。
当我调用 class2 时,我的图像视图无法显示 class2images(从 image201 到 image400)
但是,class1Images(从 image001 到 image200)仍在 app 中。
我认为class1图像仍在内存中,因此class2图像无法添加到内存中。
我想在调用 class2 时删除 class1images。
当我调用下一节课时,它将删除内存中的旧图像并替换为新图像。
但是,我的应用是使用故事板和 ARC 开发的。
所以,我不能在 ARC 模式下手动释放内存。
有什么办法可以去除内存中的旧图片?
- (void)viewDidLoad{
[super loadView];
self.view.backgroundColor = [UIColor grayColor];
ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
ScrollView.pagingEnabled = YES;
NSInteger numberOfViews = 200;
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
// Create a UIImage to hold Info.png
UIImage *image1 = [UIImage imageNamed:@"Image001.jpg"];
UIImage *image2 = [UIImage imageNamed:@"Image002.jpg"];
:
:
UIImage *image200 = [UIImage imageNamed:@"Image200.jpg"];
NSArray *images = [[NSArray alloc] initWithObjects:image1,image2, . . . ,image200,nil];
ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0,self.view.frame.size.width, self.view.frame.size.height)];
[ImageView setImage:[images objectAtIndex:i]];
[ScrollView addSubview:ImageView];}
ScrollView.contentSize = CGSizeMake(self.view.frame.size.width*numberOfViews,self.view.frame.size.height);
[self.view addSubview:ScrollView];}
【问题讨论】:
-
显示一些代码.. 不明白你是如何连接的
-
这根本与内存中的内容无关。请使标题更具描述性以及您要做什么
-
你们班的角色是什么?并且您是否将图像动态添加到滚动视图。请按照 Daji-Djan 所说的发布代码。
-
很抱歉给您带来不便,我在运行时将图像添加到数组中。
标签: ios xcode ipad cocoa-touch