Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7

前端 未结 30 2542
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 12:47

Starting in iOS7, there is additional space at the top of my UITableView\'s which have a style UITableViewStyleGrouped.

Here is an example:<

相关标签:
30条回答
  • 2020-11-22 12:56
    override func viewWillAppear(animated: Bool) {
            self.edgesForExtendedLayout = UIRectEdge.None
    
     //  OR
    
    self.sampleTableView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
    
       //OR
    
     self.automaticallyAdjustsScrollViewInsets = false
            }
    
    0 讨论(0)
  • 2020-11-22 12:57

    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.

    0 讨论(0)
  • 2020-11-22 12:58
    self.automaticallyAdjustsScrollViewInsets = NO;
    

    try, you can deal with it!

    0 讨论(0)
  • 2020-11-22 12:58

    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))
    
    0 讨论(0)
  • 2020-11-22 12:59

    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
    }
    
    0 讨论(0)
  • 2020-11-22 13:00

    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.

    0 讨论(0)
提交回复
热议问题