2

Since I updated my app to iOS 7 new GUI I have a problem that I can't solve.

My app consists in a scrollable TableView. Trouble is that TableView scrolls underlying top bar, means that table doesn't consider top bar and extends till the top and it's ugly to see.

enter image description here

I tried removing check on "Extend edges under Top Bars" but it's the same.

How can I solve this?

Matte.Car
  • 2,007
  • 4
  • 23
  • 41

2 Answers2

1

One solution is: set the table view's contentInset and scrollIndicatorInsets to have a top inset of 20. The table view will still underlap the status bar, but it will be completely visible when scrolled all the way.

If you don't like that solution, and you want a permanent empty area behind the status bar, you will have to change the way you pin/position the top of the table view, to allow for the status bar. How you do this depends on whether you are using auto layout. If you are, just pin to the top layout guide. If you are not, you will have to use the "delta" field provided in the nib editor.

If you are using a UITableViewController, however, you are not in charge of the top of the table view; it is a full-screen view and it is the view controller's main view. This is quite a troublesome situation, actually. I have resorted to two solutions:

  • Put the whole thing into a UINavigationController in order to get the nav bar to "run interference" for me.

  • Or, embed the table view controller in a custom parent view controller just so that I can position the top of the table view.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • It might help you to read this article that I wrote about transitioning from iOS 6 to iOS 7: http://radar.oreilly.com/2013/09/making-the-leap-to-ios-7.html – matt Oct 17 '15 at 15:06
  • Ok, `contentInset ` move table 20px down and it's good, but, scrolling, table keep overlying top bar. – Matte.Car Oct 17 '15 at 15:08
  • I said that in my answer. And I told you what to do if you don't like that. – matt Oct 17 '15 at 15:40
  • But I'm working with UITableViewController so I can't work with constraints; it has full screen table, how can say to Controller "leave 20 px on top"? I tried in Storyboard, using `.contentSize`, `.bounds` but nothing... – Matte.Car Oct 17 '15 at 16:00
  • Okay, good answer. I've had the same problem myself. In that case, believe it or not, what I usually do is put the whole thing into a UINavigationController in order to get the nav bar to "run interference" for me. If you don't want to do that, and you still want exactly the same interface you used to have, you will have to embed your table view controller in a custom parent view controller so that you _can_ position the top of the table view! – matt Oct 17 '15 at 16:10
  • Added that to my answer. – matt Oct 17 '15 at 16:13
0

In UINavigationController I created an UIView, which goes under status bar but in front of embed controller (the Table), so table disappear behind this view and status bar is always on top.

var patch: UIView!

override func viewDidLoad() {
    super.viewDidLoad()

    patch = UIView(frame: CGRectMake(0, 0, view.bounds.width, 20))
    patch.backgroundColor = UIColor.redColor()
    self.view.addSubview(patch)
}

Then I make it disappear when screen goes in Landscape (in iOS9, status bar automatically disappear in Landscape) and make it reappear when screen goes in Portrait.

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        patch.hidden = true
    } else {
        patch.hidden = false
    }
}
Matte.Car
  • 2,007
  • 4
  • 23
  • 41