serdar aylanc serdar aylanc - 23 days ago 9
Swift Question

Swift +hide or remove a UIView

I have

UITableViewController
, on top of it I placed an
UIView
and inside it there is a
UICollectionView
.

When collectionView data is empty I want to remove the
UIView
. I tried:

self.collectionView.removeFromSuperview()


and

self.collectionView.hidden = true


These removes the
UIView
but there is an empty space above my
tableview
. How can I get rid of it?

Edit: added a photo of my storyboard. Recommended View is not inside the tableviewheader.

enter image description here

Answer

It looks like the collection view is a table header view (the way you have positioned it in the storyboard).

Try setting it to nil if data is empty

self.tableView.tableHeaderView = nil

Comments