将大量本地映像(106X2)加载到2个UIScrollView中

时间:2012-09-11 19:03:53

标签: objective-c xcode xcode4 ios4 uiscrollview

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


}

1 个答案:

答案 0 :(得分:0)

30-40 kb filesize表示保存这些图像所需的实际内存。

最好使用UITableView并根据需要动态加载图像,或使用Apple的一个UIScrollView示例:PhotoScrollerScrollViewSutie进行演示平铺。