在我的应用程序中,我在内存问题上有一个小问题。
我的编码技能还不够完善。
我的代码使用了我真正需要的四次内存。
我怎样才能改变我的编码?
我的代码是
-(void)viewDidAppear:(BOOL)animated
{
UIScrollView * ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height-88)];// 44(UpperNavigtionBar),-88(Upper+Lower)
ScrollView.pagingEnabled = YES;
// Create a UIImage to hold Info.png
UIImage *image1 = [UIImage imageNamed:@"Image-001.jpg"];
UIImage *image2 = [UIImage imageNamed:@"Image-002.jpg"];
UIImage *image3 = [UIImage imageNamed:@"Image-003.jpg"];
UIImage *image4 = [UIImage imageNamed:@"Image-004.jpg"];
UIImage *image5 = [UIImage imageNamed:@"Image-005.jpg"];
UIImage *image6 = [UIImage imageNamed:@"Image-006.jpg"];
UIImage *image7 = [UIImage imageNamed:@"Image-007.jpg"];
UIImage *image8 = [UIImage imageNamed:@"Image-008.jpg"];
UIImage *image9 = [UIImage imageNamed:@"Image-009.jpg"];
UIImage *image10 = [UIImage imageNamed:@"Image-010.jpg"];
UIImage *image11 = [UIImage imageNamed:@"Image-011.jpg"];
UIImage *image12 = [UIImage imageNamed:@"Image-012.jpg"];
UIImage *image13 = [UIImage imageNamed:@"Image-013.jpg"];
NSArray *images = [[NSArray alloc] initWithObjects:image1,image2,image3,image4,image5,image6,image7,image8,image9,image10,image11,image12,image13,nil];
NSInteger numberOfViews = 13;
for (int i = 0; i < numberOfViews; i++)
{
CGFloat xOrigin = i * self.view.frame.size.width;
UIImageView * ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height-88)]; // -88(Upper+Lower)
[ImageView setImage:[images objectAtIndex:i]];
[ScrollView addSubview:ImageView];
}
ScrollView.contentSize = CGSizeMake(self.view.frame.size.width*numberOfViews, self.view.frame.size.height-88); // -88(for adding Image View as subview)
[self.view addSubview:ScrollView];
}