2014-03-24 4 views
0

내 프로젝트에 landing_load1 @ 2x ... landing_load4 @ 2x 파일이 있습니다. (단, 비 망막 파일 없음)NSBundle mainBundle pathForResource : @ 2x가 포함되어 있지 않으면 작동하지 않습니다.

이 코드는 작동합니다

for(int x=1; x < 5; x++){ 
    NSString * imageTitle = [NSString stringWithFormat:@"landing_load%[email protected]", x]; 
    UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:@"png"]]; 

    [loadingImages addObject:loadingImage]; 
} 

그러나이 작동하지 않습니다

for(int x=1; x < 5; x++){ 
    NSString * imageTitle = [NSString stringWithFormat:@"landing_load%i", x]; 
    UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:nil]]; 

    [loadingImages addObject:loadingImage]; 
} 

을 그리고이 작동하지 않습니다

for(int x=1; x < 5; x++){ 
     NSString * imageTitle = [NSString stringWithFormat:@"landing_load%i", x]; 
     UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imageTitle ofType:nil]]; 

    [loadingImages addObject:loadingImage]; 
} 

질문 : 명시 적으로 @ 2x를 호출하거나 파일 유형을 지정할 필요가 없다는 것을 알고 있습니다. 따라서 모든 fi를 명시 적으로 작성하지 않으면 왜 작동하지 않는지 알 수 있습니다. 르네 이름?

참고 : '비'작업의 예에서

답변

1

기록

NSString * imageTitle = [NSString stringWithFormat:@"landing_load%i", x]; 

당신이 어떤 리소스에 대한 그래픽 파일 한 쌍을 가지고 있다는 것을 의미한다. 그

NSString * imageTitle = [NSString stringWithFormat:"landing_load%[email protected]", x]; 
같은 1. 뭔가 : 또는 당신은 단지 " [email protected]"이 경우 대안은 전용 "filename.png"를 "별칭"로 사용할 수 있습니다, 당신은 두 가지 변종이

또는 모든 리소스에 대해 두 파일 ("filename.png"및 "[email protected]")을 모두 보유하고 있어야합니다.

1

아이 패드 4에서 테스트 당신은 ofType 매개 변수에 nil을 언급하지 않았습니다. 당신이

-[NSBundle pathForResource:ofType:] 

방법을 사용하고 있기 때문에

UIImage * loadingImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]  pathForResource:imageTitle ofType:nil]]; 

변화 png에, 트릭 :

+1

이 질문을 업데이트했습니다. @ 2x를 추가하지 않으면 여전히 작동하지 않습니다. 감사합니다 – user3456115

0

을 수행해야합니다, 당신은 당신이 "로 제공 한 두 번째 매개 변수에서 자원 유형을 지정해야 png "코드가 작동한다고합니다. "filename.png"와 "[email protected]"모두 -

0

@ 2x는 [NSBundle pathForResource:ofType:]의 일부로 취급되지 않고 [UIImage imageNamed:]의 일부로 처리됩니다. 전자를 사용하기 만하면됩니다.

+1

imageNamed는 이미지를 발표하지 않으며 메모리 문제를 일으 킵니다. – hasan83

관련 문제