重用出现问题,把老的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;
}