2012-08-03 6 views
0

저는 약 50 개의 이미지를 표시하고 30 번째 이미지에 도달하면 응용 프로그램이 메모리 문제로 인해 충돌합니다. 내가 아는 모든 방법을 시도했지만 여전히 문제는 해결되지 않았습니다. 제발 도와주세요.응용 프로그램이 uiimageview로 인해 작동을 멈 춥니 다.

NSLog(@"%d",nn); 
nn ++; 
NSLog(@"%d",nn); 
NSMutableArray* arr2 = [[NSMutableArray alloc]init]; 
arr2 = [Database executeQuery:@"select * from cartoon"]; 
if (nn == [arr2 count]) 
{ 
    nn = 0; 
} 
NSMutableDictionary* dict1 = [arr2 objectAtIndex:nn]; 
NSLog(@"%@",dict1);    
NSString * both_name = [NSString string]; 
both_name = [both_name stringByAppendingString:[dict1 objectForKey:@"mainpk"]]; 
both_name = [both_name stringByAppendingFormat:@". "]; 
both_name = [both_name stringByAppendingString:[dict1 objectForKey:@"name"]]; 
NSLog(@"both %@",both_name); 
label1.text = both_name; 
imgv.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg",[dict1 objectForKey:@"name"]]]; ` 
+0

이 코드는 어떤 문제와 관련이 있습니까? 명백한 것 이외의 어떤 종류의 도움을 원하십니까? (즉, 30 개의 이미지가 메모리에 맞지 않으면 30 개의 이미지를로드하지 마십시오)? –

+0

내 대답을 확인하십시오 : http://stackoverflow.com/questions/11758454/need-to-create-photo-slider-using-photo-library-photos-in-iphone/11760226#11760226 도움이 될 수도 있습니다. – Iducool

+0

내 대답 확인 : [http://stackoverflow.com/a/11791089/1132951] (http://stackoverflow.com/a/11791089/1132951) 도움이 될 수 있습니다. –

답변

0

메모리에 50 개의 이미지를로드하려고하는데 문제가 없을 것으로 예상하십니까? 파일 크기는 얼마나 큽니까?

필요할 때/표시 할 때 이미지를로드하는 것이 좋습니다. 실제 이미지를 이미지 정보 (이름, 크기, 기타)에서 분리하여 시스템에로드하고 자리 표시자를 대신 표시하십시오. 그런 다음 특정 이미지를 표시하면 실제 이미지를 메모리에로드하고 표시하십시오.

0

코드 [dict1 objectForKey : @ "mainpk"]은 문자열을 반환하지 않습니다. 코드에서

오류 : 아래 라인 아니오 키를 사용하여 사전을 만드는에서

.

NSMutableDictionary* dict1 = [arr2 objectAtIndex:nn]; 

그런 다음 잘못된 키를 통해 문자열에 액세스하십시오. 문자열에 잘못된 값을 덧붙이

[dict1 objectForKey:@"mainpk"]]; 

[both_name stringByAppendingString:[dict1 objectForKey:@"mainpk"]]; 

이이 작동합니다 :)

충돌합니다 :

NSMutableDictionary* dict1 = [[ NSMutableDictionary alloc ] initWithCapacity: 0]; 

[dict1 setObject: @"test" forKey: @"mainpk"]; 
[dict1 setObject: @"test1" forKey: @"name"];  

NSString * both_name = [NSString string]; 
both_name = [both_name stringByAppendingString:[dict1 objectForKey:@"mainpk"]]; 
both_name = [both_name stringByAppendingFormat:@". "]; 
both_name = [both_name stringByAppendingString:[dict1 objectForKey:@"name"]]; 
NSLog(@"both %@",both_name); 
0

당신은 많은 것을로드 할 수 없습니다 사진을 한 번에. 메모리가 충분하지 않습니다.

  1. 은 당신이
  2. 당신이
  3. 이 imageNamed를 사용하지 마십시오 (당신이 어떤 종류의 미리보기를해야하는 경우 작은 축소판을 사용) 필요한 것보다 이미지가 어떤 큰하지 마십시오 보여주는 무엇로드 : 그것을 이미지를 저장하고 램을 먹는다. 대신 imageWithFile :을 사용하십시오.
관련 문제