Rak*_*esh 6 cocoa-touch objective-c ios uicollectionview uicollectionviewcell
我试图UICollectionViewCell在集合视图中隐藏一个.虽然我做的时候我很成功
cell.hidden = YES; //or cell.alpha = 0.0;
Run Code Online (Sandbox Code Playgroud)
但滚动后,单元格再次出现.我也尝试过以下方法:
UICollectionViewLayoutAttributes *layoutAttr = <get the layout attribute>//I'm succesfull here
layout.hidden = YES;
[cell applyLayoutAttributes:layoutAttr];
Run Code Online (Sandbox Code Playgroud)
我认为这可能是因为我正在使用该dequeReusable..方法因此正在重新使用该单元格,但我也试图隐藏该collectionView:cellForItemAtIndexPath:方法中的单元格无济于事.在这里它似乎甚至没有工作.
为什么这不起作用?我怎么能隐藏一个UICollectionViewCell?
编辑:包括执行collectionView:cellForItemAtIndexPath::
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.layer.cornerRadius = 12.0f;
cell.backgroundColor = [UIColor colorWithRed:0.830 green:0.899 blue:1.000 alpha:1.000];
cell.selectedBackgroundView = [[UIView alloc]initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor lightTextColor];;
cell.layer.borderColor = [UIColor blackColor].CGColor;
cell.layer.borderWidth = 2.0f;
cell.hidden = YES;
UILabel *lbl = (UILabel *)[cell viewWithTag:10];
NSArray *interArray = numberArray[indexPath.section];
[lbl setText:[interArray[indexPath.row] stringValue]];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
这应该隐藏所有细胞吗?但不,不会发生.
由于隐藏单元格本身似乎不起作用,您可以使用与集合视图的背景颜色相同的颜色向单元格添加子视图,也可以隐藏单元格的内容视图,该视图可以正常工作:
cell.contentView.hidden = YES;
cell.backgroundColor = self.collectionView.backgroundColor;
Run Code Online (Sandbox Code Playgroud)
只有在为单元格设置背景颜色时才需要第二行.
| 归档时间: |
|
| 查看次数: |
9216 次 |
| 最近记录: |