【发布时间】:2014-04-19 06:10:29
【问题描述】:
在我使用的 UICollectionView 中,cellForItemAtIndexPath 完美运行并最初显示 collectionView。即 collectionView.reloadData 第一次成功执行。 当使用以下代码重新加载时
[self.galleryCollectionView reloadData]
单击按钮会导致崩溃。我已启用 Zombie 对象并显示错误
[CVCell release]: message sent to deallocated instance 0xa4f26c0.
下面是 cellForItemAtIndexPath 方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionVieww cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"myCell";
CVCell *cell = (CVCell *)[collectionVieww dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.cellid=indexPath;
cell.delegate=self;
cell.containerImage.delegate=self;
return cell;
}
我的 ViewDidLoad 调用下面的方法来创建 collectionView。
-(void) createCollectionView
{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//This is the size of a single cell courtesy:varuns research.
[flowLayout setItemSize:CGSizeMake(179, 224)];
flowLayout.minimumInteritemSpacing=45;
flowLayout.minimumLineSpacing=100;
flowLayout.sectionInset = UIEdgeInsetsMake(20, 30, 20, 5);
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
self.galleryCollectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, self.view.frame.size.height-120) collectionViewLayout:flowLayout];
[ self.galleryCollectionView registerClass:[CVCell class] forCellWithReuseIdentifier:@"myCell"];
[self.galleryCollectionView setDataSource:self];
[self.galleryCollectionView setDelegate:self];
self.galleryCollectionView.backgroundColor=[UIColor clearColor];
[self.view addSubview:self.galleryCollectionView];
[self.galleryCollectionView reloadData];
}
有什么解决方法可以建议吗? 提前致谢
【问题讨论】:
标签: ios objective-c ipad ios6.1