UITableView reloadData tableView

2018-12-03  本文已影响6人  浩然爸
- (void)initSubviews {
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    _tableView.estimatedRowHeight = 44; 
    _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.minimumInteritemSpacing = 0;
    flowlayout.minimumLineSpacing = 0;
    flowlayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowlayout];
    _collectionView.scrollEnabled = YES;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerNib:[UINib nibWithNibName:@"ApplyPatrolImageCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"ApplyPatrolImageCollectionCell"];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [self.collectionBGView addSubview:_collectionView];
    [_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.collectionBGView);
    }];
}
702C493F-B488-4078-A2F7-56F95D30AE77.png
- (void)setDataArray:(NSArray<UIImage *> *)dataArray {
    _dataArray = [dataArray copy];
    
    int count = (int)_dataArray.count;
    if (count % 3 == 0) {
        _heightConstraint.constant = count / 3 * collectionItemHeight;
    } else {
        _heightConstraint.constant = (count / 3 + 1) * collectionItemHeight;
    }
    
    [self.collectionView reloadData];
    
}

解决办法

- (void)initSubviews {
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    _tableView.estimatedRowHeight = 400; //设置数值大一些,防止闪屏出现
    _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
}
上一篇 下一篇

猜你喜欢

热点阅读