我需要在UICollectionView上显示大约300个图像。我添加了自定义的UICollectionViewCell和子视图UIImageView,现在当我尝试在Web服务器上显示UICollectionView上的图像时,它显示大约150个图像,然后显示低级内存的应用程序崩溃。下面是我的代码,请让我知道我做错了什么。UICollectionView应用程序崩溃在iPhone上显示大量图像
-(void)updateView {
for (int i = 0; i < m_nPhotoCount; i ++)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *imageURL = [NSURL URLWithString:[aryList objectAtIndex:i]];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
if(image == nil)
{
NSLog(@"kashif");
}
else {
[self.imageArray addObject:image];
}
dispatch_sync(dispatch_get_main_queue(), ^{
[collectionView reloadData];
});
});
}
}
#pragma mark - UICollectionView Datasource
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return [self.imageArray count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"GalleryCell";
GalleryCell *cell = (GalleryCell*)[cv dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.imageView.image = [self.imageArray objectAtIndex:indexPath.row];
return cell;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
return [[UICollectionReusableView alloc] init];
}
您好,以前我已经尝试过使用UITableView的SDWebImage它没有工作,请你帮我用UICollectionView进行缓存。 – user1237473 2013-03-19 05:58:48
@ user1237473你的意思是“It Did not Work”,你在你的viewController中导入了UITableView特定的图像缓存头文件,用于缓存Tableview中的图像? – 2013-03-19 06:08:02