Reputation: 2230
I have a subview in a tableView, positioned above the cells and added via the storyboard.
When I click the upgrade button in the UpgradeView, I called upgradeVIew.removeFromSuperview() which removed the UpgradeView as expected. However, it didn't push the cells up like I expected, and it just left a gap.
In order to rectify this, I also call upgradeView.frame.size.height = 0, which makes the cells push up as well.
Why doesn't removeFromSuperview() collapse the subview?
Upvotes: 0
Views: 203
Reputation: 15400
UITableView manages its own direct view hierarchy (not your custom cells, but the table headers, footers, sections, rows of cells which it creates and manages and for you). It isn't designed to respond to external changes to this view hierarchy. So it simply doesn't notice that you removed the table header view from its parent view.
However as pointed out in another reply, if you set tableHeaderView
to nil, which uses the documented way to change the table header, then the UITableView will respond accordingly.
Upvotes: 1
Reputation: 437
That view is considered as a tableview header so if you make it nil then it will automatically move up.
tableView.tableHeaderView = nil
Upvotes: 0
Reputation: 100533
removeFromSuperview doesn't make the collapse , what does is hooking the height constraint and make it's constant = 0
self.upgradViewHeightcon.constant = 0
self.view.layoutIfNeeded()
upgradeVIew.clipsToBounds = true
Upvotes: 1