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

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

    I had the same fix as arielyz. Once I moved the UITableView to be not the first subview of the parent view, it went away. My space was 20 px, not 35.

    I wasn't able to recreate it in a portrait xib, only a landscape xib. I'll file a radar bug later if I can reproduce it in a simple demo app.

    0 讨论(0)
  • 2020-11-22 13:02

    I was helped by the following:

    YouStoryboard.storyboard > YouViewController > Attributes inspector > Uncheck - Adjust scroll view insets.

    0 讨论(0)
  • 2020-11-22 13:02

    While using grouped TableView use this to avoid border cutting in viewWillAppear

    self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
    
    0 讨论(0)
  • 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 
    }
    
    0 讨论(0)
  • 2020-11-22 13:05

    use this one i think this help...

     - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
     {
        return 0.005f;// set this according to that you want...
     }
    
    0 讨论(0)
  • 2020-11-22 13:07

    For IOS 7 if you are allocing a tableview in a view controller you may look into

    self.edgesForExtendedLayout = UIRectEdgeNone;
    

    your problem seemed similar to mine

    Update:

    Swift in iOS 9.x:

    self.edgesForExtendedLayout = UIRectEdge.None
    

    Swift 3 :

    self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)
    
    0 讨论(0)
提交回复
热议问题