Reputation: 3541
I have a UITableView that I set up to grow dynamically depending on the content, by setting:
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension
My UITableView consists of a headerView and bodyView to which I insert other subviews after setting up.
I set up my cells with the follow rx:
viewModel
.map { $0.cellViewModels }
.bind(to: tableView.rx.items(cellIdentifier: "MyCell", cellType: MyCell.self)) { [unowned self] (row, viewModel, cell) in
cell.viewModel = viewModel
// Tried adding the following with no luck:
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
.disposed(by: disposeBag)
the cell's viewModel call's a setup() method with it's didSet, as follows:
var viewModel: CellViewModel? {
didSet { setup() }
}
In my setup, I add a subview to the bodyView of my cell depending on some other factors. ie I may add a picture, a bit of text, etc.
The problem is, when I add my subview to the bodyView of my cell, the cell's height is staying the original height that it was in the xib, and not resizing at that point to accommodate the new view. I've tried calling self.layoutIfNeeded()
after adding the subview, but no luck. How can I resize my cell after adding a subview to it?
Upvotes: 0
Views: 440
Reputation: 14030
You can call tableView.beginUpdates()
followed by a tableView.endUpdates()
call. Without anything in between.
Upvotes: 1