I have two buttons which i add it in one in table-footer and other one in table-header,i know how to hide the headerview of the table using this codetable.tableHeaderView.hidden = YES;
but the problem is there is still space in the top portion of the table.That space is equal to the header-view size,but the view is hidden .It still has the space.How can we disable the table-header by removing this space.I hope you genius developers understand my question.Please help me. Thanks in advance.
As I mentioned before there are two ways to add a header and footer view, but there are also two ways using just code. The first way will use set the tableViewHeader property on the tableview and the second way will use UITableViewDelegate methods.
There are two approaches that can help to hide a table header with the help of JavaScript. They are discussed below: Approach 1: Select the header using a CSS selector and modify the style property such that the value of the display property is set to none. This will hide the selected table header element from the page.
Let's start by creating a UIView subclass with single label which will act as a HeaderView. We expect this UILabel to be multiline to demonstrate our ability to support self-sizing table view headers. Next, inside your viewDidLoad method add following piece of code to instantiate Component and assign it as a header view
The footer is basically the same as the header but there can be a catch if you only want a footer view. To only have a footer view, you will need to add a prototype cell, that will allow you to add a footer view below the cell.
Instead of hiding the header view you should do,
tableView.tableHeaderView = nil
And later if you want to show it then just assign it again,
tableView.tableHeaderView = tableHeaderView;
In Swift:
class myTableViewController: UITableViewController { @IBOutlet var tableHeaderView: UIView! private func toggleHeaderView() { if tableView.tableHeaderView == nil { tableView.tableHeaderView = tableHeaderView } else { tableView.tableHeaderView = nil } } }
on your Storyboard, simply drag a UIView in to the table view. It will "magically" become the table view header (if you do another one, it will become the table view footer). HOWEVER you must click on that header view, and drag the referencing outlet to the table view controller, and link it to "tableHeaderView" ... that part is not "magic".
Note that because of the "!" in the declaration, you have to remember to drag the link on Storyboard or you'll get a runtime error during testing, so that's a good thing.
Try:
tableView.tableHeaderView?.removeFromSuperview() tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude)) tableView.layoutIfNeeded()
Set an UIView with height as CGFloat.leastNonzeroMagnitude instead of '0'. This will remove the blank space appearing at the top after removing the tableViewHeader. This worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With