iOS 重用 collectionViewCell时出现文字层叠

重用出现问题,把老的Cell里控件全部清除

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

    PGNoteCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    //定义一个用来保存所有控件的数组
    NSArray *subViews = [[NSArray alloc]initWithArray:cell.subviews];
    //遍历所有控件
    for (UIView *subview in subViews) {
    //移除控件
        [subview removeFromSuperview];
    }

    PGAddText *model = self.data[indexPath.row];


        myUILabel *label = [[myUILabel alloc]initWithFrame:CGRectMake(0, 0, 94, 130)];

        label.numberOfLines = 0;

        label.text = model.text;
        label.textAlignment = NSTextAlignmentCenter;

        label.verticalAlignment = VerticalAlignmentTop;

        [cell addSubview:label];


    return cell;

}
posted @ 2015-12-16 04:02  嘣嚓嚓  阅读(360)  评论(0编辑  收藏  举报