Starting in iOS7, there is additional space at the top of my UITableView
\'s which have a style UITableViewStyleGrouped
.
Here is an example:<
override func viewWillAppear(animated: Bool) {
self.edgesForExtendedLayout = UIRectEdge.None
// OR
self.sampleTableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
//OR
self.automaticallyAdjustsScrollViewInsets = false
}
To be specific, to remove tableviewHeader space from top i made these changes:
YouStoryboard.storyboard > YouViewController > Select TableView > Size inspector > Content insets - Set it to never.
self.automaticallyAdjustsScrollViewInsets = NO;
try, you can deal with it!
So I was trying every method here, and this time none of them helped. My case was a grouped table view on iOS 9. I don't really know why and how I found out this one, but for me, setting the tableViewHeader
with a UIView
with at least 0.01
height worked out. CGRectZero
didn't help, nothing really helped:
tableView.tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 0.01))
This is the solution for iOS 10 using Swift 3:
You can get rid of top and bottom paddings by implementing the following methods from the UITableViewDelegate
.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
{
return CGFloat.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
{
return CGFloat.leastNormalMagnitude
}
I think making UIEdgeInsets -35 0 0 0 is tedious. In my case, I implemented tableView: heightForHeaderInSection: method and it has a potential to return 0.
When I changed 0 to 0.1f, the problem just went away.