Boris
Boris

Reputation: 11713

UITableView first rows are cut-off under top bar

I have a UITabBarController with two UITableViews, all were created in the storyboard.

The problem is that in the second tableview the first few lines of the table are under the top bar, this doesn't happens with the first tableview, even if I change the order of the views the first will work perfectly and the second will present the problem, so the one that was working perfectly now presents the same problem because is the second item of the tabbar controller.

I don't have much code to show because I didn't create the tableviews programatically.

Upvotes: 5

Views: 4357

Answers (2)

Git.Coach
Git.Coach

Reputation: 3092

For any newly created iOS >7.0 app I suggest you take a deeper look at autolayout. For all my old iOS 6 apps I solved it like this:

In your UITableViewController interface:

  bool _hasStatusBar;
  bool _hasStatusBarHeight;
  UIView *_blendView;

In your UITableViewController implementation file:

-(void)viewWillAppear:(BOOL)animated{
  _hasStatusBar = NO;
  _blendView = nil;
  [self.tableView reloadData];
}

-(void)viewWillDisappear:(BOOL)animated{
  _hasStatusBar = NO;
  _blendView = nil;
}

- (void) viewDidLayoutSubviews {
    // WTF APPLE!?
  if (!_hasStatusBar) {

    int topBarOffset = 20;

    _hasStatusBar = YES;
      // Fix for iOS 7 overlaying status bar
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {

      CGRect viewBounds = self.view.bounds;
      _blendView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
      [_blendView setBackgroundColor:COLOR_MAIN];
      [_blendView setOpaque:YES];
      [_blendView setAlpha:1.00];
      UIView *whityMacWhite = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewBounds.size.width, topBarOffset)];
      [whityMacWhite setBackgroundColor:[UIColor whiteColor]];
      [whityMacWhite setOpaque:NO];
      [whityMacWhite setAlpha:0.80];
      [_blendView addSubview:whityMacWhite];
      [self.view.superview addSubview:_blendView];
    }
  }
}

Upvotes: 0

FeichengMaike
FeichengMaike

Reputation: 448

Not sure exactly based on your description, but a couple possibilities come to mind:

  1. Check your view controller attributes inspector in IB. Look for "Extend Edges" option under View Controller, and uncheck "Under Top Bars" if it is checked.

  2. In ios7, there appears to be a behavior in UIScrollView and all subclasses whereby the content inset and offset is automatically adjusted, sometimes not very well. You can try disabling that either in code or IB (see link for how: iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView)

Upvotes: 9

Related Questions