Hide/show search bar with pressing a button - uitableview

I have a tableview with a search bar. All is working fine but now I want a button to hide/show the search bar. This functionality is what my question is about.
Now I have created a bar below the screen where I have created a button for this. In code, there is a void function which can be filled with the code I am looking for. Just to give you an impression of how the code looks like. Right now it is empty.
I've done some research and I came up with bringSubViewToFront and sendSubViewToBack, HeadsUpUI sample app. The idea I had was that I could show the search bar by bringing it to front, put OVER the table view layer, while setting the tableview 44 pixels lower with content offset or so.
Likewise, sending the search bar layer to back, BEHIND the table view to hide it. So in the void function I tried something with [parentview sendSubViewToBack:child view] but to no effect. So my question is: how do I hide or show my search bar while having a table view and a navigation bar and a bar below with the button to do so?
Kind Regards,
John

Use like -
childview.hidden = YES;
EDIT 1-
childview.hidden = YES;
[parentview sendSubViewToBack:childview];
[tableView reloadData];
Hope it work for you.

You can use IBOutlate to your searchBar and then use this outlate to show or hide the search bar
Also don't forget to connect it with your searchBar in xib

Related

Do you have to put the UISearchBar in a UITableView?

I would like to use a UISearchBar and put it towards the bottom of a screen in order to search for available names through an API call. I want to have this SearchBar as part of a sign up form. However, when I put the SearchBar on the screen where I would like through the Storyboard, it does not show up when I run the app on the simulator. When I looked up this issue, everyone is putting the searchbar in a tableview. Am I not using the correct UI element for my cause?
The reason your search bar is not on the screen is probably because you didn't set constraint correctly or it was hidden or covered by some other view.
And for your second half of the question, I myself never put a search bar on a UITableView itself. Some apps put a search bar on the first cell of a table view but you have to scroll to make it show up. I myself always prefer to put it on the navigation controller on the top of the screen so that it will always be there and ready for user to search anything.

Embed Search bar controller in navbar

I am looking to create something similar to this, where there is a search bar in the Navigation bar. The photo below displays what I currently have in my storyboard. I would like for it to look something like the photo below that, without the customizations to the UI. I have tried placing the search bar below the navigation bar but it takes up more space that I would like and looks cluttered and unprofessional, can anybody help me here?
There are several links on SO explaining how to do this already. Check out the following: UISearchBar in navigationbar, Displaying search bar in navigation bar in iOS 8. If neither of those seem to work for your situation explain 1) What method you tried and 2) Why it's not working. You may even add some of your sample code to show how you are attempting to integrate a solution and that it's not working.
You should add tableview and search bar programmatically. By doing so, search bar does not scroll while your tableview scrolls up and down.

Hide normal UITableView when using Search Display Controller

Both my UITableView and searchResultsTableView have a clear background color. How can I hide the normal UITableView when I'm typing into the search bar of the searchResultsTableView? I've tried hiding tableView, but it hides both tableviews. See my interface builder setup below:
I've also read the post here:
Hide UITableView when searchResultsTableView displayed
However, my Search Display Controller is not being added to the tableview, only the Search Bar is. So I'm not sure how to fix this issue.
Any help is appreciated. Thanks!
You can use the method [subView removeFromSuperview] in this case. Whenever there is a need to display the searchResultsTableView just remove the UITableView from the superview and add the searchResultsTableView in place of that by using method [self addSubview:searchResultsTableView]

iOS. Navigation controller toolbar - customize example

I'm newbie with Xcode, I'm learning it and trying to make my app.
Now I would like to put Navigation Bar func at the bottom of the screen with some customize.
I turn on "Shows Toolbar" at Navigation Controller and put my button there, but I cannot customize it.
Everything that I found about customizing Navigation Bar at the top of the screen or about customizing TabBar when people are talking about bottom of the screen.
Please, can you give me a code examples to build something like this at the bottom of the screen:
https://dl.dropboxusercontent.com/u/1338320/nav.png
Thanks in advance!
I'm not sure what you are trying to customize (button or bar) but when there is a bar at the bottom of the screen that is not a tab bar it is a tool bar not a navigation bar. The two are related but they each have their own class. Tool bars use UIToolBar not UINavigationBar. The tool bar is independent of the navigation controller and the two work together well. For any views that don't want a tool bar just set it to hidden in -viewDidAppear: (you will need to un hide it in views that use it).
dimimpou is right. You can accomplish this by using a UITabBarViewController and one UIBarButtonItem for "ADD ONE" and "MY STATS".
If you get lost in references(I sometimes get lost too), I may provide a simple example.
Note that if the interface provided by UIKit doesn't meet your need you can:
Use category over UITabBar or UITabBarItem.
If 1. doesn't work sadly you'll have create your own view controller which is simulate UITabBarViewController(requires some time, but it's worth)
Edit:
You can use a UINavigationController inside a UITabBarViewController.
You can easily do this. The way I understand it, you want this "Toolbar" to show from a button in the navigation bar. Just put a tab bar with what you need and make it show when the user presses the button on the navigation bar. on this buttons action put this code: self.tabBar.hidden = NO; and on the storyboard uncheck the bar visibility option. Hope it helps!

iOS: table view's title bar covered by navigation bar unexpectedly

I'm developing a simple UI for an iOS app.
what I've done is I developed it into a table view which has a navigation controller associated to it and had it laid out in Storyboard.
Everything seems working fine, except the navigation bar accidentally cover the view's title bar "Click to select item" as shown in the pictures below.
the first picture is when it first shows on the screen.
the second one illustrates when I drag the title bar off the covering navigation bar.
what do i do to get completely rid of this?
In Interface Builder, select your view controller and on the attributes inspector turn off Layout: Wants Full Screen. Then, your layout will automatically adjust its size to make room for the navigation bar.
Add this code in your viewDidLoad method
self.navigationController?.navigationBar.translucent = false
It works for me, since you've the same problem with me, I think it's work for you as well.
where u want hide navigation bar use this line
self.navigationController.hidden = YES;

Resources