How to display a UITableView when UISearch is clicked. - ios

I am creating an app and need the user to select an activity. I want them to be able to search through the activities as there are a lot in the list. I want to just have a search bar on the main view,(with placeholder text that says select activity.) When they click in the search bar, I want a table view to appear with the list of activities, and then I want them to be able to search the table view. I know how to do the search features of the search bar but I don't know how to make it pull up the table view, or how to dismiss the table view after they select one. And I want it to display the name of the activity in a label after it is dismissed. Any suggestions will help.
Thanks!

You should use UISearchDisplayController it makes things much easier.
It manage the second UITableView so you don't need to do it yourself.
To dismiss the search table view when ever you want, call - [mySearchController setActive:NO];
Take a look at those tutorials
Implementing A Basic Search with UISearchDisplayController and Interface Builder
UISearchDisplayController with NSPredicate

Related

Show typeahead popover while user is typing

I'm trying to do something like the following:
As you can see, a popover shows up as you start typing, and updates the results as you type. My question is regarding the UI and how to actually implement it.
How can I show a custom popover when the user starts typing? Is it possible to load a custom view into a popover? Additionally, what would I need to do if I wanted to also include an image view in each typeahead result?
Good question, which most beginners have. Follow my instructions given below.
First create a view controller and design it as you wanted it to be and include a Search Controller and implement it's delegate functions in the view controller.swift file(Hope you know to work with delegates for controllers,else just google it...It's pretty easy).
Then add a Tableview in center of the view for viewing the results like shown in your question & and add a custom cell into the table view and then setup a custom class file for that cell exactly like how you works with tableview controller.Use just the basics of tableview stuffs.
Setup outlets and all for the controls and buttons.
Create an array named 'filteredResults' or name it as you like to reload the tableview data whenever the text is changed in search bar.
To detect and call your function while user changes text in search bar,You can use didTextChanged delegate function of search bar.
Note though that it's better to find everything else by your own so that you feel confident about yourself when you solve the problem at the end.

First button of UITableView as Search as well as Add textfield

If you see the screenshot below, its a view from iOS Files app which lets you select tags for a file.
I want to make a similar Tableview which lets user either select existing items or add new items. But I also want the add textfield to be a search field. That is, when the user starts typing there, he also gets search results from the existing items.
The way I am planning to implement this is...
Two table views.
One has a static cell to 'Add' and is not vertically scrollable.
Right underneath is the second table view with existing itmes, which is vertically scrollable.
when the user taps and starts typing in the textfield, there is a search side by side, in the second table view and the user can select an item from it as well.
When there are no matching results, an add button is highlighted and the user can add a new entry.
I want to know what is the best way one can implement such behaviour?
Also,
(In terms of UI Design)
Should one make use of the UISearchBar instead of a textfield?
Or, is it better to simply use the UISearchController?

iOS : How to display search results in another table view ? And how to show suggestions while searching?

Currently, what I am showing search result same tableview.
Now, I want to show results in another table view.
Here is one example of search & suggestion.
Please drag another tableview in view and when you are going to search then display that data in upper table and hide and show the upper table on the basis of search. Also create an outlet of upper tableview and apply condition in TableViewDelegate and DataSource.

iOS: Need to add an Add button to a search bar

I need a search control that allows a user to search for something, then if they don't find it they push an add button to add it. I need the add button to display while the user is typing the text to search for, I'm thinking to the right of the text. If I put the button in the navigation bar, it doesn't display while the user is searching.
I want to use a Search Bar and Search Display Controller as I need the functionality of displaying results as the user types. The first answer here -- Adding button to left of UISearchBar -- doesn't seem to work with the Search Display Controller. When the user activates the search field, it disappears.
I have been down several rabbit trails on this:
In the second answer here -- Adding button to left of UISearchBar -- I see it recommended to override the Bookmarks button. That is very clever and works, but I can't figure out how to get the "official" Add button image to override with. The simulator doesn't seem to have the images anymore (?), and I don't like the idea of hardcoding something in my code anyway. I'd rather (re)use Apple's Add button icon, but I can't figure out how to do that.
I played around with creating a subclass of UISearchBar that is loaded from a nib that has the search bar and the button, but I'm realizing if I go down that path I think I have to reimplement the interface for UISearchBar and forward all of the method calls to the "real" UISearchBar that I am managing. That seems gross.
I tried just creating a view that subclasses UISearchBar and just dynamically adds the button at initialization time. But on that path I am very bogged down in the constraints. The constraints for the text field in the search bar are up a couple of levels in the view hierarchy, and I'm pretty sure there is at least one constraint up there that I will need to remove, agreed? (because the text field is currently constrained to extend to the end of the search bar).
I also tried the same subclass and trying to just set the positions of the controls in layoutSubviews, but when I do that I find myself having to position all the child controls in the search bar (including the Cancel button, etc.), and that seems wrong.
I'm still in learning mode, and I'm not on a tight schedule. I would like to do this the "right" way. Meaning I'd like to reuse existing code and functionality and just add an add button. What is the "right" way to approach this?
Thanks!

searchResultsTableView takes entire screen on ipad

I am working on a app for the iPad which has a tableView on the left and a view on the right. We are not using the UISplitViewController.
I have been able to setup filtered results using the Search Display Controller and a search bar, but the search results take up the entire screen.
Ideally, I would like to have the search results only take up the same amount of screen as our tableView. Or, barring that, have a way to dismiss the search results when 'didSelectRowAtIndexPath' is activated.
I'm not sure what code I should post. I'm using the code from the Apple code sample: TableSearch.
on the comment below: something like this..?
[self.searchDisplayController.searchResultsTableView setFrame:myTableView.view];
By default, table views take up the whole screen, but there is nothing stopping you from setting their frame.
Just call -setFrame on the searchResultsTableView property of your search display controller.

Resources