2011-08-23 5 views
1

나는 단추 클릭 후 다른 폴더에서 이미지를 선택해야하는 아이폰 애플 리케이션에 대한 작업을하고 있습니다. UI에 5 개의 UIButton이 있으며 5 개의 이미지 폴더에는 각각 약 100 개의 이미지가 있습니다. 모든 UIButtons 이미지에 동일한 배열을 사용합니다. 나는 다음과 같은 기능에 의해 배열을 채우기 : 나는 두 번째 클릭에서 또 다시 메모리 누수를 얻고있다동일한 NSMutableArray Resuch

-(void)playAnimations:(NSString*)animationName:(int)photoCount 
{ 

NSString *photoPathName; 
UIImage *object = [[UIImage alloc]init]; 

for (int i=1; i<photoCount+1; i++) 
{ 
    NSString *[email protected]""; 
    if (i<10) { 
     imagesName =[photoPathName stringByAppendingFormat:@"000%d",i]; 
    } 
    else if(i>9 && i<100) 
     imagesName =[photoPathName stringByAppendingFormat:@"00%d",i]; 
    else if(i>99 && i<1000) 
     imagesName =[photoPathName stringByAppendingFormat:@"0%d",i]; 

    object = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imagesName ofType:@"png"]];//[UIImage imageNamed:imagesName]; 
    [self.arrayImagesName addObject:object]; 

} 
self.animationImage.animationImages = self.arrayImagesName; 

self.animationImage.animationDuration =durationTime ;// defaults is number of animation images * 1/30th of a second 
self.animationImage.animationRepeatCount = 1; // default is 0, which repeats indefinitely 
[self.animationImage startAnimating]; 
} 

(이것은 첫 번째 클릭에 적절한 실행) 및 응용 프로그램이 충돌을 가져옵니다.

어디서 실수합니까? 도와주세요/제안 해주세요.

감사합니다. 당신이 버튼을 누르면

for (int i=1; i<photoCount+1; i++) 
{ 
    // some code 
    UIImage *object = [[UIImage alloc]initWithContentOfFile:[[NSBundle mainBundle] pathForResource:imagesName ofType:@"png"]]; 
    [self.arrayImagesName addObject:object]; 
} 

이, 당신의 self.arrayImagesName 배열을 사용,

UIImage *object = [[UIImage alloc]init]; 

당신이 루프에서이 object 변수를 초기화해야하지 않습니다

답변

1

나는이 문제라고 생각합니다 동일한 이미지를 추가하십시오.