2015-05-26 50 views
0

在我的應用程序的其中一個視圖中,我想用以下代碼顯示由多個jpg圖像製成的不同動畫...我的設備無法顯示圖像陣列,但無法找到單獨的圖像

for (i = 0; i <= HighPic; i = i+1) { 

     [self.imageArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%i", imageName, i] ofType:@"jpg"]]]; 
    } 

    float imageCount = [[[self.selfContent objectAtIndex:overPath] valueForKey:@"lastImageNumber"] floatValue]*2-1; 

    imageView.animationImages = self.imageArray; 

    [imageView setAnimationRepeatCount:0]; 
    imageView.animationDuration = (imageCount/25); 
    [imageView startAnimating]; 

這個模擬器內工作正常,但是當我在我的設備上運行它時,self.imageArray等於null。如果我不是寫:

[imageView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@0", imageName] ofType:@"jpg"]]]; 

它顯示右圖,甚至在設備上,但只是沒有動畫...

的原因,我沒有使用

[self.imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%@%i", imageName, i]]]; 

是因爲它佔用了太多的內存......

在此先感謝!

+0

在哪裏分配/定義'self.imageArray'? – Larme

+0

它在我的.h文件中 @property(nonatomic,weak)NSMutableArray * exerciseImageArray; – Damiri

+0

他意味着你必須在添加對象之前初始化數組''self.imageArray = [NSMutableArray new];' – LoVo

回答

0

我自己修復了代碼。當我去.h文件我看到imageArray被設置爲weak,所以我用strong替換它,並修復它:)