iOS 7 UITableView: How to remove space between navigation bar and first cell

前端 未结 15 2355
Happy的楠姐
Happy的楠姐 2020-12-04 07:15

Description of the problem: with iOS 7 in grouped UITableView there is a gap between the top of the table view and the first cell.

The strange part is th

相关标签:
15条回答
  • 2020-12-04 07:44

    I realize this was answered a long time ago, but for anyone else running into a similar situation, I'll share what ended up working for me:

    If you're using a xib, select the top level view and set 'Status Bar' to 'None' in the Simulated Metrics area of the Attributes Inspector. Fixed my spacing issue right up.

    0 讨论(0)
  • 2020-12-04 07:45

    There was a space above the UITableView itself, and also between the cells. Found my solution in 2 different answers above..posting it again so that nobody misses both solutions.

    This removed the space from above :

    self.automaticallyAdjustsScrollViewInsets = NO;
    

    and this removed the spaces below the cells : Setting the 'Style' attribute of the UITableView to 'Plain'

    0 讨论(0)
  • 2020-12-04 07:49

    I was seeing this extra space at the top of one of my table views in a very strange situation.

    After I added a UIScrollView as the root view of my first controller in my navigation stack, if I presented the next controller as a Show Detail segue, my next controller would have the space above its table view.

    The solution for me was to change the segue to Present Modally and everything went back to normal.

    The strangest part of the segue changing was that before I added my root view being a UIScrollView, my Show Detail segue was presenting the next controller modally. Yet after I added the root UIScrollView, the Show Detail segue was pushing on the next controller (which was not what I wanted).

    0 讨论(0)
  • 2020-12-04 07:53

    Had a similar problem, even setting automaticallyAdjustsScrollViewInsets to NO. This solved for me:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
    {
        return CGFLOAT_MIN;
    }
    
    0 讨论(0)
  • 2020-12-04 07:53

    In the UIViewController.h iOS9 SDK have a method:

    @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES
    

    is not a property, so

    self.automaticallyAdjustsScrollViewInsets = NO; 
    

    should be

    -(BOOL)automaticallyAdjustsScrollViewInsets{   
         return NO;
    }
    
    0 讨论(0)
  • 2020-12-04 07:55

    Just add this in you ViewDidLoad method

    self.automaticallyAdjustsScrollViewInsets = NO;
    
    0 讨论(0)
提交回复
热议问题