我有 2 个滚动视图,我需要将 106 个图像加载到每个滚动视图中,下面是我正在使用的代码,但是当我尝试在我的 iphone 4 上测试它时它崩溃了。
每张图片大约 30-40KB,所以大小不是原因。
如果您有任何想法,我将非常感谢!
- (void)viewDidLoad
{
[super viewDidLoad];
Images = [[NSMutableArray alloc]init];
Slogans = [[NSMutableArray alloc]init];
for (int i =1; i<=106; i++) {
int r = i-1;
[self.Images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%da.jpg",i]]];
[self.Slogans addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];
NSLog(@"%d.jpg",i );
NSLog(@"%da.jpg",i );
NSLog(@"Images count: %d",self.Images.count);
NSLog(@"Slogans count: %d",self.Slogans.count);
//Images
CGRect frame;
frame.origin.x = self.ImagesScrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.ImagesScrollView.frame.size;
UIImageView *ImagesSubview = [[UIImageView alloc] initWithFrame:frame];
ImagesSubview.image = [self.Images objectAtIndex:r];
[self.ImagesScrollView addSubview:ImagesSubview];
[ImagesSubview release];
//Slogans
CGRect Sframe;
Sframe.origin.x = self.SlogansScrollView.frame.size.width * i;
Sframe.origin.y = 0;
Sframe.size = self.SlogansScrollView.frame.size;
UIImageView *SlogansSubview = [[UIImageView alloc] initWithFrame:Sframe];
SlogansSubview.image = [self.Slogans objectAtIndex:r];
[self.SlogansScrollView addSubview:SlogansSubview];
[SlogansSubview release];
}
[SpageControl setNumberOfPages:Images.count];
[pageControl setNumberOfPages:Images.count];
self.ImagesScrollView.contentSize = CGSizeMake(self.ImagesScrollView.frame.size.width * Images.count, self.ImagesScrollView.frame.size.height);
self.SlogansScrollView.contentSize = CGSizeMake(self.SlogansScrollView.frame.size.width * Slogans.count, self.SlogansScrollView.frame.size.height);
}