我对这些问题有类似的问题,但似乎无法解决我的问题..
我在CollectionView
中有UIViews
个自定义cell
,在reloadData上重新添加自定义UIViews
,而不删除已经显示的内容。这是我的cellForItemAtIndexPath ...
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *collectionViewCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LiveTileCell" forIndexPath:indexPath];
NSDictionary *cellDataDictionary = [self.dataArray objectAtIndex:indexPath.row];
UIView *customView = [[UIView alloc] initWithFrame:collectionViewCell.contentView.frame];
customView.tag = 1002;
LiveTileView *liveTile = [[LiveTileView alloc] initWithFrame:CGRectMake(0, 0, collectionViewCell.frame.size.width, collectionViewCell.frame.size.height)];
liveTile.tag = 1001;
[liveTile initialize:[cellDataDictionary valueForKey:@"backgroundColor"] titleFont:[cellDataDictionary valueForKey:@"titleFont"] titleText:[cellDataDictionary valueForKey:@"titleText"] titleColor:[UIColor whiteColor] titleImage:[cellDataDictionary valueForKey:@"titleImage"] badge:[[cellDataDictionary valueForKey:@"badge"] intValue] detailViewImage:[cellDataDictionary valueForKey:@"detailViewImage"] compactView:nil isLiveTile:[[cellDataDictionary valueForKey:@"isLiveTile"] boolValue] animationTime:[[cellDataDictionary valueForKey:@"animationTime"] floatValue] elementIndex:indexPath.item];
[customView addSubview:liveTile];
[collectionViewCell addSubview:customView];
return collectionViewCell;
}
任何帮助都会很棒..提前感谢
答案 0 :(得分:1)
试试这个
UICollectionViewCell *collectionViewCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LiveTileCell" forIndexPath:indexPath];
// for(UIView *view in collectionViewCell.contentView.subviews)
for(UIView *view in collectionViewCell.subviews)
{
for(UIView *subView in view.subviews)
{
[subView removeFromSuperview];
}
[view removeFromSuperview];
}
// write your code here