Using UISearchDisplayController in a child controller - ios

I made a tabbed controller where the tabs are on top. Underneath the tabs I have a subview which will contain a tableViewController as a child controller.
The tableViewController has a searchBar and a UISearchDisplayController. The problem is, when the search is activated, the UISearchDisplayController jutts out above the frame of the tableView and covers a bit of the tabs.
I believe this is caused by the SearchBar expanding itself on top to cover up the navigationBar.

Sorry but, why are you using a search display controller?
In this case is easier if you use just a tableView with a searchBar as well as your tab.
Then you can develop the same behaviour of the searchDisplayController.
There are developers that have never used the searchDisplayController. In general i use that just when i have a tableViewController within so just a tableView and a searchBar. But in your case, i would not use that. Take your life easier trust me ;)

Related

My UITableView Gets ShiftedDown

I have a UITableView that when first displayed it displays correctly with the first row appearing on top. When I select a cell another UITableView is presented. If I used the back button on the UINavigation Bar the original UITableView is shifted down with a blank space between the UINavigation Bar and the UITableView.
I am not using story boards. I am using XIB files. I am also using a sliding menu that I got the code for from Ray Wenderlich's web site.
When I slide back the main screen over the first UITableView it goes back to its proper position. But then when I select an entry again the issue described above appears.
I found another post that seems to provide an answer to the issue. This post says to make some adjustments like to the translucent settings or the auto-layout settings but doesn't give specifics.
Here is that post: Container View getting pushed down as if it had a UINavigationBar?
Thanks,
Glenn
Add
self.automaticallyAdjustsScrollViewInsets = NO;
in viewDidLoad, of the UIViewController where you have the shifting table view

Swift: Add segmented controller to a navigation bar, and keep the title + nav buttons

I'd like to add a segmented controller to a navigation bar, below the title.
At the moment, I've got a storyboard UITableViewController with a CoreData-sourced dynamic table, embedded in a UINavigationController. I'd like the UISegmentedController to differentiate the sorting of the table.
There seems to be obj-C solutions available stackoverflow.com/questions/29480433/ and stackoverflow.com/questions/18813563, but I'm looking for a Swift solution, that resembles the native apps. I've also tried putting the segmented controller into a table cell with little success (can't get the action recognised). I'd prefer not to abandon the table view controller.
Any suggestions?
I replaced the UITableViewController with a UIViewController and UITableView, then added the UISegmentedController to a UIToolBar positioned below the UINavigationBar.
I used removeShadow for the navbar, then clipsToBounds for the toolbar. I also added another View to simulate the bottom shadow on the toolbar (because I couldn't get the toolbar shadow/background position function to work).

UINavigationBar inside UITableViewController

I have some static cells that I want to display, so I have a UITableViewController. There is also a NavigationBar in this scene that contains some buttons at the top. The setup looks like this:
If I had a UIViewController that contained a UITableView in it, the setup would look like:
So, the question is:
Why does the Navigation Bar have to be embedded inside the UITableView when using a UITableViewController? (I have tried putting it elsewhere but IB won't let me)
I know that UITableView is a subclass of UIView, but is it OK that the top level element in the hierarchy is not a View (but a TableView)?
Thanks.
You shouldn't be placing your UINavigationBar in your UITableView. You should be putting your UITableViewController in a UINavigationController, because that will provide a UINavigationBar for you.
So if you select your UITableViewController in the storyboard, you can choose Embed In -> Navigation Controller from the Editor menu. This would be the proper way to do it.
There are two ways to use a UINavigationBar in iOS:
Embedded inside a UINavigationController (recommended)
As a standalone object
For your particular situation, I'd recommend that you put your UITableViewController as the rootViewController of a UINavigationController. That way you automatically get a navigation bar which you can customize according to your needs. In a typical user experience, when you tap some of your table view rows a new view controller will be pushed onto the navigation stack, so you'll probably end up needing a navigation controller anyway.
What if you decide to use a navigation bar as a standalone object? This is perfectly fine, you can use it inside a view hierarchy as an ordinary UIView, but you'll need to create another object that implements the UINavigationBarDelegate protocol and set it as the delegate property of your navigation bar. If you use a UINavigationController the delegate is already set and configured for you. You also need to add/remove navigation items (instances of UINavigationItem) to your navigation bar by using the pushNavigationItem:animated: and popNavigationItemAnimated: methods.
And about your question on the view hierarchy, you can use a UITableView anywhere a UIView is required. The only caveat is that a UITableView is a view hierarchy on its own and that may restrict your layout a little bit.
The way a UITableViewController works, is its root view is a UITableView. So there is no way to put the UINavigationBar anywhere other than in the UITableView.
I tend never to use a UITableViewController as it doesn't really give you much.
If you particularly want to use the UITableViewController, I don't believe that there is any real problem in having the navigation bar within the table view. You just need to make sure that you set the contentInset on the table view such that the navigation bar doesn't block the content. Though it seems a bit backward to do it this way.
My recommendation would be to just use a normal UIViewController with a navigation bar and a table view.
If you actually need functional navigation, you need to put your UITableViewController within a UINavigationController.
Hope this helps :)
Let me know if anything is still unclear.

IOS Customizing UISearchBar and Search Display

Hey I have been trying to customize a UISearch bar with display controller and have run into some issues customizing certain aspects of the search and display controllers. I'm using storyboard and am developing with the most recent version of IOS 6.
The first issue is eliminating the dark grey gradient overlay that appears when you first click on the search text view. I have tried to use the searchDisplayController:willShowSearchResultsTableView: delegate but am unable to either find the view that is being used as the gradient overlay or a property to disable it. How do I remove this view?
The second is I am having an issue with the initial animation that is triggered when the search view is clicked. The animation is supposed to expand the search bar over the UINavigationBar to allow for a larger space to view the results. This doesn't happen and the search bar stays below the UINavigationBar and the animation doesn't properly show. I have tried setting the displaysSearchBarInNavigationBar and navigationItem properties but couldn't find any way to access or set them. Could this be an issue with the fact that I'm using autolayout in my story board? I have noticed that many issues relating to the UISearchBar animations are due to autolayout being used in the .xib or storyboard file. How can I make it correctly over the navigation bar?
The third issue I am having is with over ridding the searchBarTextDidBeginEditing:(UISearchBar *)searchBar delegate method. I have subclassed the UISearchBar to allow for complete customization. Is there a way to provide a default definition for the searchBarTextDidBeginEditing: delegate method inside my custom UISearchBar subclass. I want to provide a specific style of text in the UITextView when the user clicks on the search bar and don't want to have to redefine this method in every view controller that uses the search bar. Is this possible?
Thanks for the help in solving these issues.

Adding a toolbar to a navigation controller

I am completely new to ios development and I am only interested in developing for ios5.
I have an app with some scenes, they are mostly tableviews. I also use a navigation controller
I however need to add some status text and buttons that are always visible in all scenes and thought that a toolbar added to the navigation controller should do the trick.
so i thought that i should only have to drag out a toolbar in storyboard to the navigation controller, but it does not stick there. I can add it to the bar underneath with first responder and navigation controller but that does not help me (small icons).
I can also not add it to my table view (but if i drag out a plain view I can add it there)
do I have to make my own custom navigation class that the navigate view uses and then programatically add my toolbar?
Had the same question recently. Check Attributes Inspector in your ViewController's properties in storyboard. There you can define a Bottom Bar.
Well, inside the UINavigationController, you should have something... A UIViewController for instance. You can easily add a UIToolBar by dragging the object inside the UIView of the UIViewController. What might being happening is that as the root view you have the UITableView, in that case I think you can't do that. But to better understand, just take a small print screen of your StoryBoard.
If you zoom up to 100% on the storyboard it should drag.

Resources