0
GCD를 사용하여 성능 문제를 해결하기 위해 콜렉션보기의 셀을로드하려고했습니다. 내가 ARC를 사용하고 6.1에 내장하고IOS 콜렉션 핵심 데이터에서 셀 이미지 생성 및 GCD 사용
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *slideCell =
[collectionView dequeueReusableCellWithReuseIdentifier:slideCellIdentifier
forIndexPath:indexPath];
slideCell.backgroundColor = [UIColor lightGrayColor];
slideCell.selectedBackgroundView = [[UIView alloc]initWithFrame:slideCell.bounds];
slideCell.selectedBackgroundView.backgroundColor = [UIColor redColor];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
SlideHeader *slideHeader = [self.fetchedResultsController objectAtIndexPath:indexPath];
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.frame = CGRectMake(2, 2, slideCell.bounds.size.width-4, slideCell.bounds.size.height -4);
if (slideHeader.frontCoverImage) {
NSData *frontCoverImage = slideHeader.frontCoverImage;
imageView.image = [UIImage imageWithData:frontCoverImage];
}
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *visibleCells = [self.collectionView visibleCells];
if ([visibleCells containsObject:slideCell]) {
[slideCell.contentView addSubview:imageView];
if (slideHeader.slideTitle.length > 0) {
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(slideCell.bounds.origin.x, slideCell.bounds.size.height - 30, slideCell.bounds.size.width, 30)];
titleLabel.text = slideHeader.slideTitle;
titleLabel.backgroundColor = [UIColor lightTextColor];
titleLabel.font = [UIFont boldSystemFontOfSize:18];
titleLabel.textColor = [UIColor blackColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.userInteractionEnabled = NO;
[slideCell.contentView addSubview:titleLabel];
}
}
});
}
});
return slideCell;
}
다음과 같이 세포의 로딩을위한 내 코드입니다. 그 아크 나를 위해 GCD 메모리 출시 hanld 것으로 예상하지만 난 문제로 결국 : 나는 스크롤
이 momory가 올라 갔다 :
다음은 메모리 사용의 스크린 샷 콜렉션 뷰를 위아래로 계속 볼 수 있습니다. 메모리를 해제하는 데 오랜 시간이 걸렸습니다. 메모리 사용량이 충분히 많으면 프로그램이 중단됩니다.
내 코드에서와 같이 GCD 블록에 자동 복구를 추가하려고 시도했지만 메모리를 빨리 해제하는 데 도움이되지 않습니다.
이 문제를 해결하기 위해 할 수있는 일은 무엇이 있습니까? 고맙습니다. 다음