【发布时间】:2016-01-22 15:28:37
【问题描述】:
我在collectionView 标头中有一个UILabel。标签设置为零行、自动换行和适当的前导/尾随/顶部空间约束。如果我不调用[collectionView reloadData],标签会正确扩展为多于两行的文本。一旦reloadData 被调用,标签就会回到一行……第二行消失。
- (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
if (kind == UICollectionElementKindSectionHeader) {
header = (viewRollHeader *) [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
header.rollTitle.text = [self.roll objectForKey:@"title"];
header.rollDescription.text = [self.roll objectForKey:@"info"];
[header.cancelButton addTarget:self action:@selector(exit) forControlEvents:UIControlEventTouchUpInside];
return header;
}
return [UICollectionReusableView new];
}
- (CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if (section == 0) {
CGRect labelRect = [[self.roll objectForKey:@"title"]
boundingRectWithSize: header.rollTitle.frame.size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : [UIFont fontWithName:@"Arial-BoldMT" size:32.0f]}
context:nil];
return CGSizeMake([[UIScreen mainScreen]bounds].size.width, (174.0f + labelRect.size.height));
}
return CGSizeZero;
}
【问题讨论】:
-
请贴出代码。
-
@Ismail 它在情节提要中完成。只有代码是 reloadData
-
您如何处理情节提要中
UICollectionView的所有内容???数据源/委托方法在哪里? -
@Ismail 这是我的标头方法。
-
您找到解决方案了吗?我遇到了完全相同的问题。
标签: ios uicollectionview uilabel reloaddata