我在collectionView
头中有UILabel
。该标签设置为零线,文字换行和正确的前导/尾随/顶部空间约束。如果我不打电话给[collectionView reloadData]
,标签将正确扩展为超过两行的文字。一旦调用reloadData
,标签就会回到单行......第二行消失。UICollectionView`reloadData`会导致UILabel行消失
- (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
@Ismail在故事板中完成。只有代码是reloadData – Peter
如何处理故事板中的“UICollectionView”的所有内容?数据源/委托方法在哪里? – Ismail