2011-03-16 4 views
0

ImageDemo 템플릿을 사용하고 있는데 이미지 묶음의 이미지를 코딩하면 작동하지만 앱에서 만든 디렉토리에서 이미지를로드하면로드가 없습니다. .iPad AQGridView가 묶음으로 내 UIImages를 표시하지 않습니다.

코드 : 나는 내 응용 프로그램에서 다른 장소에있는 모든 이상을 사용하기 때문에 나는이 일을 알고있는 이미지 데이터를 끌어 사용하고 그리고 난에 속성을 설정할 때이 전무를 확인하고

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index 
    { 
     static NSString * PlainCellIdentifier = @"PlainCellIdentifier"; 

     AQGridViewCell * cell = nil; 
     ImageDemoGridViewCell * plainCell = (ImageDemoGridViewCell *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier]; 
     if (plainCell == nil) 
     { 
      plainCell = [[[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0) 
                 reuseIdentifier: PlainCellIdentifier] autorelease]; 
      plainCell.selectionGlowColor = [UIColor lightGrayColor]; 
     } 
     NSString *fileName = [NSString stringWithFormat:@"%@/%@_tn.jpg",[manufacturerID stringValue], [[[self.collectionItems objectAtIndex:index] valueForKey:@"PhotoName"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]; 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsPath = [paths objectAtIndex:0]; 
     NSString *savePath =[documentsPath stringByAppendingPathComponent:fileName] ; 
     NSData *imageData = nil; 
     BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:savePath]; 
     if (fileExists) { 
      imageData = [NSData dataWithContentsOfFile:savePath]; 

     } else { 
      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"NoImageAvailableThumbNail" ofType:@"png"]; 
      imageData = [NSData dataWithContentsOfFile:filePath]; 
     } 

UIImage *myImage = [UIImage imageWithData:imageData]; 
    NSLog(@"%@", myImage); 
    if (myImage==nil) { 
     NSLog(@"NO IMAGE"); 
    } 
    plainCell.image = myImage;  

     cell = plainCell; 

     return (cell); 
    } 

I 코드 AQGridViewCell :

- (void) setImage: (UIImage *) anImage 
{ 
    _imageView.image = anImage; 
    [self setNeedsLayout]; 
} 

답변

1

거기 예제에서 nil UIImage에 대한 확인이 표시되지 않습니다. 정확히로드되고 있는지 확실합니까? 한 줄에 이미지를 만들고 다른 이미지에 설정하여 디버거에서 이미지를 볼 수 있습니다. 참고로, Kobo 앱의 캐시 된 도서 표지 이미지와 비슷한 기능을 수행합니다. 한 가지 차이점은 C 메서드를 사용하여 PNG 파일에서 UIImage를로드한다는 것입니다. 내 머리 꼭대기에있는 UIImageFromPNGData()와 같은 것입니다. (현재 아이폰이 답장하고 있습니다.)

내가 생각할 수있는 유일한 다른 점은 이미지보기가 어떤 이유로 숨겨져 있는지 여부입니다. 디버거에서 인쇄하면 크기, 레이아웃 등을 알 수 있습니다.

+0

응답 해 주셔서 감사 드리며, 로깅을 추가하고 이미지를 얻습니다. 보여줘. 어딘가에 어리석은 짓을 했음에 틀림 없어. 계속보고있어. 고마워. – Slee

+0

여전히 여기에 붙어있어, 나는 UIImage가 만들어지고 전달 된 것을 압니다. - 나는 그것들이 테스트로서 반복 될 때 메인 뷰에 추가했고, 그들은 확실히로드되었습니다. 번들에 포함 된 이미지를로드 할 수 있습니다. URL에 포함 된 위치가 없습니다. 당신이 다른 무엇을 생각할 수 있다면, 나는 그것을 감사 할 것입니다 - 도움을 주셔서 감사합니다. – Slee

+0

확인해야 할 것은 이미지보기의 프레임이 빈 rect (즉 너비/높이가 0.0)가 아니라는 것입니다. 그것은'-layoutSubviews'에서 업데이트 될 것이므로, 먼저 거기에 체크하십시오. 또한 반환 된 UIImage가 공백 또는 nil 크기 (0.0x0.0)인지 확인하여 같은 종류의 문제를 일으킬 수 있습니다. –

관련 문제