1

I have UITableView, and I put container view on top as a header like this:

enter image description here

And everything work well.

Now I would like to hide this container header view, when tap in the cell.

My first attempt was :

UIView.animate(withDuration: 0.3, animations: {
    self.containerView.frame.size.height = 0
})

witch hide the view, but don't bring cells up, what it is expected and normal, because I only change frame for container view, and not for other views.

Then I try to add constraints in storyboards, but for some reason I can't set them.

Why is that? And how do I achieve to hide container view, and bring all other cells to the top.

Jack
  • 13,571
  • 6
  • 76
  • 98
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
  • Try changing `tableview.estimatedSectionHeaderHeight = 0` – RajeshKumar R Mar 23 '17 at 08:25
  • Nop this is not helping... the results stay the same. – Marko Zadravec Mar 23 '17 at 08:32
  • I'd suggest to add the header view it as another cell and hide it (as you are hiding the first cell in the table view), it should be the first cell... – Ahmad F Mar 23 '17 at 08:33
  • once you change headerview frame height to 0 try to reasign that headerview to that table i have done same thing and its working for me – Pankaj K. Mar 23 '17 at 08:36
  • hi Prince, I didn't quite understand what you suggest. Could you please write more detailed answer. – Marko Zadravec Mar 23 '17 at 08:45
  • 1
    please check http://stackoverflow.com/questions/19056428/how-to-hide-first-section-header-in-uitableview-grouped-style – iVarun Mar 23 '17 at 08:47
  • @MarkoZadravec I have tested your issue programmatically, i have taken a view programmatically and assigned height to 100 and after 10 second i have performed a selector which make headerviews height to 0.0. and its working well. please check it. – Pankaj K. Mar 23 '17 at 09:04
  • @Prince Pleas see my image again. This is not real header as viewForHeaderInSection... It is container view, that is put on top of the table scroll view. – Marko Zadravec Mar 23 '17 at 09:08
  • yes I know its not a headerview for each section but try to asign your view as a table's header like tablname.tableHeaderView = yourview name – Pankaj K. Mar 23 '17 at 09:25
  • @MarkoZadravec Check my ans. It works for the container view. – RajeshKumar R Mar 23 '17 at 10:02

1 Answers1

1

Try this

UIView.animate(withDuration: 0.5) {
            let headerView = tableView.tableHeaderView!
            headerView.setNeedsLayout()
            headerView.layoutIfNeeded()
            headerView.frame.size.height = 0
            tableView.tableHeaderView = headerView
        }
RajeshKumar R
  • 15,445
  • 2
  • 38
  • 70