url.So의 사전 저장소 이미지를 변경할 수있는 배열이 있습니다. 응용 프로그램 캐시에 이미지를 저장하는 방법과 인터넷에 연결되어 있지 않을 때 이미지를 볼 수 있습니다.캐시에 이미지 데이터를 저장하는 방법
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString * [email protected]"CustomCell";
CustomCell *cell = (CustomCell*)[collectionView dequeueReusableCellWithReuseIdentifier:CellIndentifier forIndexPath:indexPath];
NSDictionary *dictVideo = [self.videoList objectAtIndex:indexPath.row];
[cell.indicator startAnimating];
//set title
NSString *titleVideo = [dictVideo objectForKey:@"Title"];
[cell.myLabel setText:titleVideo];
// set image url
NSString *urlVideo = [dictVideo objectForKey:@"Url"];
NSURL *url = [NSURL URLWithString:urlVideo];
cell.imageView.image = nil;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage * img = [[UIImage alloc]initWithData:data];
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(@"%ld %@ %@",(long)indexPath.row,titleVideo,url);
[cell.imageView setImage: img];
[cell.indicator stopAnimating];
});
});
return cell;
}
'캐시'를 정의합니다. 로컬 sqlite, 문서 폴더? 이미 원시 데이터가 있으므로 몇 가지 옵션이 있습니다. 예 :'[[NSFileManager defaultManager] createFileAtPath : 경로 내용 : 데이터 속성 : nil]; ' – SwiftArchitect
인터넷에서 다운로드 한 이미지를 문서의 캐시 폴더에 저장하여 이미지를 더 빨리로드하려고합니다. – HIEU
나는 여기와 같은 질문에 대답합니다. NSCache를 사용하여 이미지 데이터를 캐싱하는 것을 포함하여 ... http://stackoverflow.com/questions/15799432/poor-uicollectionview-scrolling-performance-with-uiimage/15799771#15799771 – danh