【发布时间】:2015-05-08 09:55:29
【问题描述】:
我有这种要求,如果用户选择了 1,那么我必须通过旋转 90 度来显示图像(在集合视图单元格中),如果用户选择了 4,那么我必须将图像显示为圆形。对于选择 2 和 3,按原样显示图像。
为此,我写了下面的代码。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
FilterCell *cell = (FilterCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"filterCell" forIndexPath:indexPath];
if (!cell) {
cell = [[FilterCell alloc] init];
}
if (filterScreen==1) {
cell.imgView.image = [collectionImage objectAtIndex:indexPath.row];
cell.imgView.transform = CGAffineTransformMakeRotation(M_PI_2);
}
else if (filterScreen==2) {
cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"filter_%ld",(long)indexPath.row]];
}
else if (filterScreen==3) {
cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"motiontitle_contents_%ld",(long)indexPath.row]];
}
else if (filterScreen==4) {
cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"bgm_%ld",(long)indexPath.row]];
cell.imgView.layer.cornerRadius = cell.imgView.frame.size.height /2;
cell.imgView.layer.masksToBounds = YES;
}
return cell;
}
在选择 1、2、3 或 4 时,我正在重新加载集合视图。
问题在于,如果用户在选择 1 后选择了 4,则显示后的一些图像会旋转,之后如果用户选择 2 或 3,则一些图像会旋转,而一些图像会旋转。 我曾尝试在重新加载之前删除部分here,但应用程序崩溃和日志是
*** -[UICollectionView _endItemAnimations] 中的断言失败,/SourceCache/UIKit/UIKit-3318.93/UICollectionView.m:3917
重载代码如下:
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,0)];
[filterCollectionView deleteSections:indexSet];
[filterCollectionView reloadData];
更新:
如果尝试使用 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,1)];
然后得到
*** -[UICollectionView _endItemAnimations] 中的断言失败,/SourceCache/UIKit/UIKit-3318.93/UICollectionView.m:3901
谁能帮我解决这个问题?
【问题讨论】:
-
请包含断言失败。
标签: ios objective-c uicollectionview uicollectionviewcell