UICollectionView单元格未在reloadData上清除

时间:2014-06-05 10:35:01

标签: ios objective-c uicollectionview uicollectionviewcell

我对这些问题有类似的问题,但似乎无法解决我的问题..

  1. UICollectionView reload data Issue
  2. ios UICollectionView cells not refreshing after scroll
  3. UILabel overloading in UICollectionView
  4. 我在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;
    }
    

    任何帮助都会很棒..提前感谢

1 个答案:

答案 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