iOS TableViewController Scrolling away content and navigation bar under status bar - xcode

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

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.

you can try self.edgesForExtendedLayout = UIExtendedEdgeNone;

Related

How can I make the top and bottom elements of my view controller stay in place, while the middle has elements to vertically scroll through?

I'm working in Swift 3 and XCode 8.
I tried to find the answer to this question, but maybe I don't know how to ask it properly. I'm trying to have a title bar at the top of a view controller and have a back and next button at the bottom of the view. The content in between is longer than the space that exists, so I would like the user to be able to scroll the middle, but keep the top and bottom elements anchored in place.
I've tried to use a container with another view controller that is larger than the container to make this happen, but it just resizes the child view controller.
If I'm not explaining something properly, please let me know and I will try to give more information about what I've missed.
I'm making a few assumptions about your Views:
Navigation Bar for your title
Toolbar to hold your Back and Next buttons
Try the following:
Place a Navigation Bar as seen below. Do not set any constraints.
Place a Toolbar as seen below. Again, do not set any constraints.
Place a Scroll View in the centre of your View Controller and expand it so that the top and bottom are aligned with the navigation bar and toolbar respectively. Again, do not set any constraints.
Highlight all of the Views in the View Controller and place them in a Stack View.
Pin the Stack View to the Superview. These are the only constraints that are set in the example below.

UISearchController won't stay at top in the table header view

I'm having a problem on how to tie the UISearchController at top of my UITableHeaderView. I've tried some scenarios I found here on the forum but they didn't work. It's scrolling, and I hate it. However when is active, it stays on the top. But I'd like to be on the top when is also inactive. Share some code if you have bros.
Instead of putting your UISearchController into a UITableHeaderView (which is why it's scrolling along with the table cells), add your search bar on top of the UITableView.
And if you're using a UITableViewController, please ditch that (because it doesn't play nice with views added on top of the table) and use a custom UIViewController with a table view as a subview inside of the content view.

Xcode tableview hidden behind navigation bar

Can anyone please tell me how to fix the following issue.
I am building an iPhone app using Storyboard. I have a Navigation Controller as root view and off that a view controller. On this I have a few buttons that when clicked takes you to a table view controller. All fine and well, but when I link the buttons to their respective table views, the top navigation bar obscures the top cell in the table view controller.
Does anyone know why this is happening and how I can fix it?
Also it seems to have thrown off my layouts from the view controller from which they inherit.
See attached image for a better explanation perhaps.
I believe this is the intended behavior when using the translucent navigation bar. It's semi transparent specifically so that you can see items pass behind it (e.g. a table scrolling). If you don't want this, changing the navigation bar's style to opaque should solve the problem.
Since I wanted to keep the translucence, I just added a UIView between the navigation controller and the prototype cell (width of the view, height 60). That way the first cell in the table starts beneath the navigation bar but I can still see the scrolling underneath.
This is a bug/feature in IB when you use a translucent navigation bar, the content view runs under the navigation bar. For non transparent bars the content view begins after the bar. If your content view is a UIScrollView (UITableView is a descendent of UIScrollView) the content will be automatically scrolled so as to not be hidden under the navigation bar. So the problem only exist in IB when you run the app everything should be ok.
You just need go to the Navigation Controller properties, then Simulated Metrics, and change the Top Bar to be a Transluscent Navigation Bar WITH PROMPT. And that should be it. No need for that extra UIView

Top offset of TableView embeded in Navigation Controller in storyboard

I have custom TableViewController with plain style Table View and it is embeded in Navigation Controller. I use Refresh Control on the table view and Black Translucent style of the navigation bar and all is setup in storyboard.
The first row of the table view starts right under the navigation bar item, which is ok, and the rows can scroll under the navigation bar which is semi transparent. When user starts to pull the table down to activate Refresh Control, the animation of the refresh object obviously starts at the edge of the screen under the Navigation Bar, and so the refresh object is always partially covered by the navigation bar which can confuse inexperienced users.
Is there a way to tell the TableView to avoid scrolling under the navigation bar and start the refresh control object animation right under the navigation bar? I tried to play with Scroller Insets on table view without any effect.
Thank you.
If you go into the properties for the tableview controller in your storyboard, you can change the size and positioning of the tableview to start after the navigation bar. The problem isn't an offset, but the size and position of the tableview itself. Just move the y position down to accommodate the nav bar.

Positioning UISearchBar above TableView in .xib

I'd like to make it easier for users to access the searchbar. Currently, the searchbar is above the tableview and when a user scrolls the tableview, the search bar scrolls off screen with it. Is there an easy way to position it above the tableview so it will always be visible?
I am using .xib files instead of the storyboard b/c I'd like my app to be compatible back to iOS 4.0.
Well what you could do is just place a search bar above the table view in your XIB. Or just move the search bar you've (presumably) got in your table view's header view at the moment and put it above the table. You'll also have to shrink the table by 44 pixels (the height of the search bar) and move it down so that the search bar is above it.
If you go for deleting the one in the table view's header view and creating a new one then just make sure you hook it up correctly to whatever it is that's currently using it (i.e. probably an outlet for the search bar and its delegate).

Resources