2012-09-11 71 views
0

我有2個滾動視圖,並且我需要將106個圖像加載到每個滾動視圖中,下面是我正在使用的代碼,但它在嘗試時崩潰在我的iphone 4上測試它。將大量本地圖像(106X2)加載到2個UIScrollView

每個圖像大約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

30-40 kb filesize沒有說明持有這些圖像所需的實際內存。

您最好使用UITableView並根據需要動態加載圖像,或使用Apple的UIScrollView示例之一:PhotoScrollerScrollViewSutie演示平鋪。