2012-09-25 2 views
1

NSString을 NSCache에 저장하고 있지만 NSLog에서 나에게 (null)을 제공하고 있습니다.NSCache가 항상 null (null)을 제공합니다.

내가있는 viewDidLoad에 그것을 초기화 후 나는 NSCache에 저장하려면이 코드를

cache=[[NSCache alloc]init]; 

그럼 내가 전화를 저장하는 기능은이 같은 검사를하고 그 다음

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1]; 
NSString *res = [cache objectForKey:indexPath]; 
if (!res) {      
    [email protected]"1"; 
    [cache setObject:res forKey:indexPath]; 
} 

객체있다 :

NSString *res = [cache objectForKey:indexPath]; 
if (!res) {  
    [email protected]"1"; 
    [cache setObject:res forKey:indexPath]; 
} 

불행하게도 ...

NSLog("%@",res); //always it gives me (null) 

누구든지 이전에이 문제가 있었습니까? 어떤 도움을 주셔서 감사합니다. 객체를 저장 한 후

+0

가 어디 로깅을하는거야? 초기 값이 NSNull이 아닌지 확인 했습니까? 키 복사가 차이가 있습니까 (NSCache는 기본적으로 키를 복사하지 않습니다)? –

답변

0

은 다음과 같이 확인 :

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:1]; 
NSLog(@"%@",[cache objectForKey:indexPath]); 
+0

도움을 주셔서 감사합니다. 문제는 indexPath가 적합하지 않다는 것입니다. 어쨌든 내 실수 녀석들! :) – stefanosn

관련 문제