我正在使用自动布局来计算UICollectionView的高度。因此,每当调用sizeforitematindexpath
时,我的UICollectionView就会冻结。
这是一个代码
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat height;
if ([alertheightDict objectForKey:indexPath]) {
height = [[alertheightDict objectForKey:indexPath] floatValue];
}else{
//[[LogClass sharedInstance] log:[NSString stringWithFormat:@"offscreencells %@", self.offscreenCells]];
//NotificationCustomCell *cell = [self.offscreenCells objectForKey:indexPath];
NotificationCustomCell *cell = [[NotificationCustomCell alloc] init];//my custom cell
NSMutableDictionary *dataSourceItem = [alertsArray objectAtIndex:indexPath.row];// my source array
[cell updateCell:dataSourceItem :indexPath.row : 0];// updating cell
[cell setNeedsUpdateConstraints];
[cell updateConstraintsIfNeeded];
cell.bounds = CGRectMake(0.0f, 0.0f, cellWidth, CGRectGetHeight(cell.bounds));
[cell setNeedsLayout];
[cell layoutIfNeeded];
height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
[alertheightDict setObject:[NSString stringWithFormat:@"%f", height] forKey:indexPath];
}
return CGSizeMake(cellWidth , height);
}
这里有什么不对,冻结我的应用程序