我使用故事板和 ARC 模式。这包括三个视图控制器。
每个视图控制器都有自己的类。
VC1 有 Class1.h 和 Class1.m
VC2 有 Class2.h 和 Class2.m。
在每个 m 文件中,我创建图像视图并将图像添加到图像视图中。
然后我将此图像视图添加到滚动视图中。
在这种情况下,我在 class1 中使用了大约 200 张图像后,class2 的图像无法在图像视图中显示。
起初,我认为这是内存问题。
我认为它达到了内存限制,所以它不能再次添加其他图像。
所以,我减小图像大小并重试(从 300Mb 减小到 30Mb)。
但是,它没有用。我不知道。我怎么解决这个问题?请告诉我方法。
那是我的代码。
- (void)viewDidLoad
{
[super loadView];
self.view.backgroundColor = [UIColor grayColor];
UIScrollView *ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, 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:@"Image-001.jpg"];
UIImage *image2 = [UIImage imageNamed:@"Image-002.jpg"];
UIImage *image13 = [UIImage imageNamed:@"Image-200.jpg"];
NSArray *images = [[NSArray alloc] initWithObjects:image1,image2,...,image200,nil];
UIImageView *ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
[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];
}