2014-04-01 7 views
1

내가 사용 UITabelviw 및 UICollectionviewUIImageView + AFNetworking.h를 사용할 때 메모리 압력으로 인해 종료 되었습니까?

코드에 대한 내 이미지 뷰의 이미지를 laod하는 AFnetwroking 있는 UIImageView + AFNetworking.h을 사용하고 있습니다 : 난에서 이미지를 표시하는 응용 프로그램에서를 통해이 코드를 사용하고

NSString *str = [NSString stringWithFormat:@"http://www.hdwallpapers.in/walls/lovely_roses_hq-wide.jpg"]; 
    NSURL *imgrl =[NSURL URLWithString:str]; 
    NSLog(@"ImageMB url %@",imgrl); 
    [cell.profilePic setImageWithURL:imgrl placeholderImage:[UIImage imageNamed:@"default.png"]]; 

UITableview 및 UICollectionview.My 응용 프로그램이 크래시되고 "메모리 부족으로 종료 중입니다."라는 메시지가 나타납니다.

제발 내 문제를 해결하십시오. 당신의 기본 sharedImageCache를 사용하여 가정

감사 램야

+0

한 번에 몇 개의 이미지를 사용하고 있습니까? 세포를 재사용하고 있습니까? – rounak

답변

0

, 당신은 그에서 경고 메모리가 있어야합니다.

+ (id <AFImageCache>)sharedImageCache { 
    static AFImageCache *_af_defaultImageCache = nil; 
    static dispatch_once_t oncePredicate; 
    dispatch_once(&oncePredicate, ^{ 
     _af_defaultImageCache = [[AFImageCache alloc] init]; 

     [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * __unused notification) { 
      [_af_defaultImageCache removeAllObjects]; 
     }]; 
    }); 

#pragma clang diagnostic push 
#pragma clang diagnostic ignored "-Wgnu" 
    return objc_getAssociatedObject(self, @selector(sharedImageCache)) ?: _af_defaultImageCache; 
#pragma clang diagnostic pop 
} 

보시다시피 메모리 경고가 있는지 확인합니다. 내 생각 엔 당신이 그것을 채울 때마다 아마 당신의 셀에 새로운 이미지 뷰를 추가하고있는 것일까?

더 많은 도움을 받으려면 추가 코드가 필요합니다.

0

sharedImageCache를 사용하지 않고 셀이 메모리를 재 할당하지 않습니다. 그것은 이미 uicollectionvew 정의 셀에서 생성

cell.profilepic

통해 사용하기 전 나 이미지의 크기를 변경 asepct의 라이토를 사용하여 UICollectionView 결함 레이아웃

생성되었다.

CGSize CGSizeAspectFit(CGSize aspectRatio, CGSize boundingSize) 
{ 
float mW = boundingSize.width/aspectRatio.width; 
float mH = boundingSize.height/aspectRatio.height; 
if(mH < mW) 
    boundingSize.width = boundingSize.height/aspectRatio.height * aspectRatio.width; 
else if(mW < mH) 
    boundingSize.height = boundingSize.width/aspectRatio.width * aspectRatio.height; 
return boundingSize; 
} 

크기를 계산하고 이에 대한 셀을 생성했습니다.

Photo *photoData = [self.photosListArray objectAtIndex:indexPath.item]; 

//[cell.displayImage setImageWithURL:[photoData photoURL]]; 
// Here we use the new provided setImageWithURL: method to load the web image 
NSLog(@"photo url %@",[photoData photoURL]); 
[cell.displayImage setImageWithURL:[photoData photoURL] 
        placeholderImage:nil]; 
//user profile pic 
NSString *str = [NSString stringWithFormat:@"http://www.hdwallpapers.in/walls/%@",photoData.userProfilePic]; 
NSURL *imgrl =[NSURL URLWithString:str]; 
NSLog(@"Image url %@",imgrl); 
[cell.userProfilePic setImageWithURL:imgrl placeholderImage:[UIImage imageNamed:@"default_profilepic.png"] 

이것은 내 코드입니다. 기억력을 피할 수있는 답변을 제안하십시오.

감사합니다.