Keep search bar fixed position while scrolling tableView - xcode

How can i keep the uiSearch bar i created in Xcode 4.3.3 fixed on top while scrolling the table view?
Any thoughts?

EDITED:
If u have used the Interface builder to add the search bar, make sure that it is not added as the subview of the tableview (this makes the search bar as a part of the table, which scrolls along with the table). Checkout the link below, and avoid it. This link shows how a search bar becomes a subview of the table. This is not what u want. Just drag the search bar outside of the Table view in ur interface builder, so that it becomes a part of the view.
I have added second image to show how u can find the solution to ur problem.
If u want to add the search bar programatically, then just add it as-
[self.view addSubview:mySearchBar];
Set the frame of this search bar accordingly.

how did you create them in the nib file? do not put the search bar on the UITableView. they should be separated.You can put the search bar at the top of the tableview but not on it.

Related

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.

iOS TableViewController Scrolling away content and navigation bar under status bar

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;

Can't get the most basic scrollview to work

This is not my day. I've just deleted every object from my previously completed view controller to start over because I can't get a simple scroll view to scroll. I've got a view controller that is embedded in a navigation controller. I put scroll view inside the view controller and then put two text fields inside the scroll view, one field at the top and one at the bottom.
First of all, when I run this, it won't scroll. What is the point of the scroll view if it won't scroll?
Second, I can't figure out how the relationship between the navigation bar and the scroll view works. Is the scroll view behind the navigation bar? Is it below the navigation bar? In the story board, it looks like it is behind the bar, but when I run it, my text field is pushed down so far that it looks like it is behind it.
Here are a couple of screen shots. To say that I am frustrated is an understatement. Thanks for any help getting me out of my circular problem. I appreciate it.
And here is how it looks when I run it. Notice how far down the top text field gets drawn. Also note that you cannot see the bottom text field. I am unable to scroll to this. What gives?
First of all, when I run this, it won't scroll. What is the point of the scroll view if it won't scroll?
Scroll views won't scroll by default unless their contentSize exceeds their bounds. You can force it to scroll anyway by setting alwaysBounceVertical to YES.
Second, I can't figure out how the relationship between the navigation bar and the scroll view works. Is the scroll view behind the navigation bar? Is it below the navigation bar? In the story board, it looks like it is behind the bar, but when I run it, my text field is pushed down so far that it looks like it is behind it.
Yes, in iOS 7, by default, a scroll view will start at y = 0, behind the nav bar. You use the contentInsets property to push it down. The view controller has an automaticallyAdjustsScrollViewInsets property that can handle this for you.

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

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