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

前端 未结 30 2925
隐瞒了意图╮
隐瞒了意图╮ 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 13:02

    Thanks to the answer by @Aurelien Porte. Here is my solution

    Cause of this issue:-

    1. a UITableView doesn't like to have a header with a height of 0.0. If what's you're trying to do is to have a header with a height of 0, you can jump to the solution.
    2. even if later you assign a non 0.0 height to your header, a UITableView doesn't like to be assigned a header with a height of 0.0 at first.

    In ViewDidLoad:-

    self.edgesForExtendedLayout = UIRectEdge.None
    
    self.automaticallyAdjustsScrollViewInsets = false
    

    No Need For Something Like This :-

    self.myTableview.contentInset = UIEdgeInsetsMake(-56, 0, 0, 0)
    

    In heightForHeaderInSection delegate:-

    if section == 0
        {
            return 1
        }
        else
        {
            return 40; // your other headers height value
        }
    

    In viewForHeaderInSection delegate :-

    if section == 0 
    {  
       // Note CGFloat.min for swift
       // For Objective-c CGFLOAT_MIN 
       let headerView = UIView.init(frame: CGRectMake(0.0, 0.0, self.myShaadiTableview.bounds.size.width, CGFloat.min)) 
       return headerView
    }
    else
    { 
       // Construct your other headers here 
    }
    

提交回复
热议问题