0

我有 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);


}
4

1 回答 1

0

30-40 kb 的文件大小并没有说明保存这些图像所需的实际内存。

您最好使用 UITableView 并根据需要动态加载图像,或者使用 Apple 的 UIScrollView 示例之一:PhotoScrollerScrollViewSutie,其中演示了平铺。

于 2012-09-11T19:30:17.310 回答