我有这个代码来管理一个collectionview
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [images count];
}
- (PhotoCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoCell *cell = [gridPhoto dequeueReusableCellWithReuseIdentifier:@"photocell" forIndexPath:indexPath];
NSMutableDictionary *record = [images objectAtIndex:[indexPath row]];
if ([record valueForKey:@"actualImage"]) {
[cell.image setImage:[record valueForKey:@"actualImage"]];
[cell.activity stopAnimating];
} else {
dispatch_async(imageQueue_, ^{
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[record objectForKey:@"url"]]];
dispatch_async(dispatch_get_main_queue(), ^{
[record setValue:[UIImage imageWithData:imageData] forKey:@"actualImage"];
[collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
});
});
}
return cell;
}
如果 imageQueue_ 完成它的工作并填充整个集合视图,它就可以正常工作;当我退出视图时我遇到了问题
- (IBAction)back:(id)sender{
[self.navigationController popViewControllerAnimated:YES];
}
在这种情况下,如果 collectionview 没有全部填充图像,则在执行返回操作时会出现此错误:
[PhotoGalleryViewController numberOfSectionsInCollectionView:]: message sent to deallocated instance 0x1590aab0
问题出在哪里?