I need to have a search bar for a table view that displays a list of data, not sure whether I should use one table view for both displaying and searching, or have separate table views for display and search respectively.
Single table view:
+ feels easier to implement by just switching data source
- extra work if I want to maintain the scroll position (after searching) of the display table view
Separate table views:
+ no extra work needed to preserve scroll offset of the display table view
- extra work to switch between display and search modes
Is there anything critial I missed? What is the recommended way?
Update:
I need the search bar to stick on top, so it can't be the tableHeaderView of the table view (which scrolls when table view scrolls), or section header view because I've got different sections.
Thanks!
I've used a single table view and used a read only property to filter the array of items based on the search text.
I stored the original data in Property X and based on the text entered in the search bar i filtered the data returning by the Property (readonly) Y and used as the table data source.
Using the search bar delegate method you can then filter the contents of the table as the user enters text into the search bar.
The first one is the recommended way to implement the searching functionality. Managing the datasource is easier then to handle the two different tableviews.
You can try for UISearchController which provides the searchBar with a TableView and can have delegate methods to handle the case.
Here and here are some good tutorials to do the same.
Related
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.
I'm trying to create an app where multiple lists can be switched between using a button. Does anyone have any advice on the best way to do this, preferably using storyboard (my Swift skills leave a lot to be desired)? Right now I only have one list (a TableView) which is contained in a Container View, along with two other regular Views, one at the top and one at the bottom of the Container View, with the TableView in the middle. I want to have a button in the top regular View that switches between multiple TableViews. I want the number of TableViews to be dynamic, starting with one, but then the user can add additional tables as they need. Any advice on how to set this up would be greatly appreciated! Is it even possible to create a prototype TableView? Is that the way to go here? I've found a couple of Answers on Stack Overflow regarding multiple tables on a single screen, but these lists wouldn't be on a single screen, they would only be viewable one at a time: if you want to see the second list, you have to press the "Next List" button (in the View at the top of the Container View), and the first list disappears and is replaced with the second. Thanks everybody!
Don't change table views, change datasources. Use a single table view as you have it, and one array for each mode that the table is in (call those arrayA and arrayB). Another array-type variable -- call it theModel -- should be set to point to A or B.
The datasource methods will answer the count of theModel, and get values for the cells from theModel. When the user presses the button...
self.theModel = (self.theModel== self.arrayA)? self.arrayB : self.arrayA
self.tableView.reloadData()
// everywhere else, use theModel as the datasource
In our project we've a requirement like this.
Our webservice sends the neccesary data to create views in our applications
These datas are consist of multiple views with an order.
For example it can send a data like this
[{"ViewType":"Table","datas:":[....]},
{"ViewType":"PieChart","datas":[...]},
{"ViewType":"BarChart","datas":[...]}]
So we are going to show all these views in the same view controller , and when the user first open the view he/she will see the table then he'll scroll down and see the piechart etc...
Is something like that possible with any kind of design pattern in iOS
If it is how?
Thanks
You can use the table view or collection view. Each cell can have the single view, on the basis of count of the views, you can set the number of cells of the tableview or collection view. Disable the horizontal scrolling if required.
I have table view with a Search Bar above it. My intention is to have users enter a query in the search bar and have the table view populate with results - either when the user presses enter or as they're typing.
After reading a number of tutorials, I selected the Search Bar and Search Display Controller for the Search Bar. However, it seems this controller is less of an enter-query-then-display-results tool than a filter-existing-table-view-data tool. This means I'm coming upon a table view that already has all the data and is filtered as I type -- what I'd like is to come upon an empty table view and have it populate.
I was wondering if there was a way to use the Search Bar and Search Display Controller to achieve the effect I want or it there was a preferred way?
These two Ray Wenderlich tutorials are great for learning how to implement search into your UITableViews.
This tutorial covers the basic Search Bar with Objective-C.
This tutorial covers the Search Bar using Swift.
Basically (very basic implementation level here) you will want to know if you are searching or not. If you are not searching, in your tableView:numberOfRowsInSection: method you can return 0, otherwise return the count of the results. Then in your tableView:cellForRowAtIndexPath: method you can customize the cell that is being displayed based upon the results.
When using UISearchDisplayController you'll have two UITableViews. The one in your search view controller. So assuming you are hooking up both UITableView's dataSources to your UIViewController, just check which table is being passed in and return nothing if it's not for the search.
For example
- (NSArray *) _sectionArrayForTable:(UITableView *) tableView {
if (tableView == self.searchDisplayController.searchResultsTableView) {
// Return your search results
}
// Show nothing when not searching
return 0;
}
When the text changes, you will want to determine which results to show for that string and update some array or dictionary. Implement the tableview datasource methods to show the contents of that array/dictionary and call reload table when the text changes
i want to display name phone number and salary of a employee in an ipad in the form of table with multiple columns for that i take three table views and successfully displayed data in them . the table views are scrolling independently.but i want to implement if one table view is scrolled the second and third must be moved parallel. can any one please tell me how to implement that one....
If you want all your UITableViews dependants and scrolling at the same time, there is no reason to create multiple table view.
You can just create un custom UITableViewCell with the layout and style you want! This will be easier and will consume less resources.
find out position of cell in first table depending on that change position of cell in next table.
You can use following property of UITableView - – scrollToRowAtIndexPath:atScrollPosition:animated: