1.父tableview 的cell里面嵌套 子tableview,父級cell高度自適應(yīng)撐起
1)子級cell高度固定,可以通過數(shù)組數(shù)量*cell的高度計算tableview的高度,撐起父級cell
在父級cell里面進行刷新高度,方法如下:
a.在賦值數(shù)組是刷新tableview
[self.tableView reloadData];
[self.contentView layoutIfNeeded];
[self layoutIfNeeded];
b.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
NSInteger index = 1;
index = self.model.goods.count;
CGFloat height = (100 + 16) * index;
self.tableViewHeightCons.constant = height;
return index;
}
2)子級cell高度自適應(yīng)時
通過一下方法獲取子tableview的高度
pragma mark reload 完tableview,獲取tableview的contentSize
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath )indexPath {
if([indexPath row] == ((NSIndexPath)[[tableView indexPathsForVisibleRows] lastObject]).row){
dispatch_async(dispatch_get_main_queue(),^{
self.tableViewHeightCons.constant = tableView.contentSize.height;
});
}
}
3.collectionView高度自適應(yīng)方法:
[self.CollectionView reloadData];
// 延遲一秒去執(zhí)行 成功回調(diào)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.CollectionViewHeightCons.constant = self.infoCollectionView.collectionViewLayout.collectionViewContentSize.height;
});