iOS TableViewController Scrolling away content and

2019-09-13 01:55发布

问题:

I'm using a TableViewController and I've added my own navigation bar on top to match the other tabBar pages that I have.

I had to place at the top an empty view to lower the starting point of the table view so it wouldn't cover my navBar, which was already annoying.

Now it looks fine except that when I scroll up my list both navBar and TableView go under the status bar.

I want my navBar to stay where it is and the TableView not to go under the status bar when scrolling.

For starting I can't add any other stuff in my scene if not under the table view and i get that that's causing the nav bar to follow the tableview up so that's part of the problem..

Xcode 7.1 swift 2.0 iOS 9

回答1:

When creating this kind of structure (table + other elements), the best approach is to actually have a ViewController that contains a TableView and additional elements (like your navigation). Do not try to put elements, that are not part of the table itself inside the table.

Here is an example of the structure, where I have intentionally coloured the custom view (in your case the navigation) orange. As you can see, it is outside the table. This way the showing and scrolling of the table is completely separated from the other elements.



回答2:

you can try self.edgesForExtendedLayout = UIExtendedEdgeNone;