Reloading / Displaying searchResultsTableView of UISearchDisplayController after search method iteration is finished - iphone

I have modified the code of Apple's sample iOS project TableSearch in order to use it for searching a webservice by parsing its contents. Everything I have implemented works fine except for one ugly detail when performing a search using the SearchDisplayController's SearchBar. I have changed the behaviour of the SearchDisplayController to make it call my search function first when the "Search" button was tapped.
The problem is that when the search iteration (which is performed in the background in an NSOperationQueue) is finished the "searchResultsTableView" (of the searchDisplayController) is not automatically displayed or not assigned the resulting content. If you then change the SearchBar's text or tap the "Cancel" button from the view which appears when you touch the search field (see TableSearch) the correct TableView appears with the search results. I simply want to have this step to be executed right after the search operation is finished, so before you interact. At this stage the "No Results" label is currently displayed. The methods "filterContentForSearchText" and "shouldReloadTableForSearchString" are unchanged from the original TableSearch project.
I have taken a look at different class references of the SearchDisplayController and its attributes but I could not find any final solution yet.
I have tried the following in a section which is definitely iterated after the NSOperation is finished but it does not seem to solve the problem.
[self.searchDisplayController.searchResultsTableView removeFromSuperview];
and
self.searchDisplayController.searchResultsTableView.hidden = YES;
These operations both have the correct view I want displayed BUT scrolling is disabled until you change the state so that the view is hidden again. It is possible to select TableView cells, though. I basically want to have this just with scrolling enabled...
Thanks in advance for your effort!

I have same problem and I just solved it. I had exactly same problem, I wanted disable instant search and when I hit search button, the table didn't load but when I clicked cancel, it loaded up. And If I scroll on table view that didn't load correct result after search, it crashed due to index out of bound.
The thing you need to do is reload searchResultTableView not current tableview. After you filter out your data by search term, put
[self.searchDisplayController.searchResultsTableView reloadData]
to reload your search result, and it will shows up after you hit search button.
Hope this help

I found that setting the searchBar.text causes searchDisplayController.searchResultsTableView be added to self.view, I solve it like this:
self.searchBar.text = #"xxxx";
[self.searchDisplayController.searchResultsTableView removeFromSuperview];

Related

Looking for a better way to hide search bar at top of view

I have several views where I want the search bar to be hidden unless the user scrolls it down to use it. I use this command to achieve this:
[self.tableView setContentOffset:CGPointMake(0, 44) animated:NO];
This works ok, but it's not ideal; any time something happens that causes the table view to reload, it has to be repositioned again.
Now I have a view where I want to completely hide the search bar from the user, meaning they can't even scroll down to get to it, but I want to keep the scope bars at the top of the table. So basically I want to scroll the search bar off the top of the view and keep it there, while leaving the scope bar portion of the control visible. setContentOffset isn't doing it for me anymore, since the user can easily undo it.
Is there an approach to this that I'm overlooking?
Thanks in advance!
Update: I never figured this out, so ultimately I changed my design.
Although it's probably a bit late, when you say "any time something happens that causes the table view to reload, it has to be repositioned again", are you saying that every time your UITableView reloads it scrolls to its top? This isn't the standard behaviour of a UITableView.
In regards to the second part of your question regarding your UISearchBar's scope, I'd strongly recommend replacing the UISearchBar with your own UISegmentedControl (that's all the scope of a UISearchBar is anyway), so that the user isn't confused by there being an off-screen UISearchBar that doesn't do anything.

uitableview's index is shrinking

I have an app very similar to address book of iphone. The entire search and index stuff is implemented using the searchdisplay controller. The problem is, from the search results when i click some cell, it actually loads a new screen and while pressing back and going to home tableview screen the index is shrinks
The possible reason which I could think is the keyboard. Is there way to make auto resizing of the index on the right side of the uitableview even after the keyboard appears for searchbar.
Do you mean resize the index to the full length of the table after you have removed the keyboard for the search has gone? If so, use can reloadSectionIndexTitles.
i got the problem in my source code. I actually release the keyboard when i am loading the view from the search results. when i come back from the newly loaded view and press the standard cancel button it loaded the tableview with half index view. Now i deleted the code which actually releases the keyboard. Then it worked normally.

UITableView -reloadSectionIndexTitles not calling data source

I'm trying to implement a UISearchBar within a UITableView, which behaves like the one in the "Artists" tab of the iPod application.
I have it hiding the navigation bar, and resizing the search box to show the "Cancel" button, etc. but am unable to get it to hide the section index titles.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
inSearchMode_ = YES; // tell sectionIndexTitlesForTableView: to return nil
tableView_.scrollEnabled = NO; // works correctly, var is definitely wired
[tableView_ reloadSectionIndexTitles]; // doesn't call sectionIndexTitlesForTableView:
...
Am I missing something? Is UITableView -reloadSectionIndexTitles broken?
Typically my response to this kind of thing would be to call reloadData, but that has the side effect of causing the UISearchBar to lose focus.
I think approach you want is along these lines (Say you have a ArtistController which you want to make searchable):
Add a sub-controller to the ArtistController called ArtistSearchController
When the search box is clicked, bring the ArtistSearchController to the front as modal (to hide artists) or add transparency if you still want to show artists in the background.
When a search term is entered, created a model for the ArtistSearchController which is the data from ArtistController, filtered using the search term, and then display it in a list view
close the modal view when the user hits cancel.
This will save you from manipulating your original controller/nav bar and give it better usability
It seems what I need to do is to use a UISearchDisplayController rather than hand-rolling my own. I was able to modify the "TableSearch" sample to use sections and section headings, and it behaves as I want it to.

How to implement "Load 25 More" in UITableViewController

I am working on an iphone application. Application loads plenty of records from a webservice into table view controller. I would like to load 25 records initially and remaining in 25 batch on clicking something like "Load 25 more" at the end of the table view.
Any help would be grealy appreciated.
Thanks
Just put a button connected to an Event in your table footer. When the button is clicked, append the next 25 results to your already existing array of items.
After that, just do a [self.tableView setNeedsDisplay]. I use that to let my table know I have extra data in the table. By using that, there is no need to scroll to the right line in the table, because it keeps its original position.
Also, why call the viewDidAppear method, this seems wrong to me, because (ofcourse) the view already appeared and all declerations and assignments you do there are re-done. Just put the stuff you need to be done while viewing the view AND when you are appending data in a seperate method and put call that method from your button-press event and from the viewDidAppear event.
I wrote an example project that does this which you can download from GitHub https://github.com/Abizern/PartialTable
I do almost the same in my application, getting 50 first records from webservice. As a table footer I have a view with next/previous buttons, that when pressed launch a fetching request for next/previous 50 results. After fetch request is processed I call viewWillAppear:animated: for my view controller and inside to [self.tableView reloadData], so these results show up in the same table view. Of cause I'm keeping the data each time only for presented results, but it depends on your needs.
Hope this helps
I wrote something that does exactly what you describe, an put it on github : https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
Hope it'll be useful.

refreshing my applicationData ( actually my Title )

I seem to be having a problem with the titles in my application.
Let me describe what is happening here.
1) starts out good with the correct image
http://img262.imageshack.us/img262/5808/picture15b.png
2) still good after clicking a cell
http://img31.imageshack.us/img31/4440/picture13dvg.png
3) after hitting the backbutton previous title remains and the last one is gone
http://img150.imageshack.us/img150/5689/picture14ltq.png
4) however after scrolling up and down fast enough the correct view appears again
http://img262.imageshack.us/img262/5808/picture15b.png
As you can see in the images above I'm using a UITableview however I'm NOT using the navigationItem title , I'm using a UILabel ( called title ).
When I click on my cells and scroll through my application everything is fine however when I click my backbutton, which is also not a standard backbutton from the tableview, but a UIBarbuttonItem it just pops the last view (and does some other stuff too)( the button below as seen in my imagelinks).
-(void)back_clicked:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
....
}
It appears that my Titles do not refresh when I press the back button(which makes sense I guess since i do not have some sort of a refresh function ).
I concluded this because when I scroll down really fast my original title comes back.
I noticed but could be wrong , bear with me here , that reloadData applies mostly to table ,cell constructing and such so I assume this is not the one I'm looking for.
So is there some sort of refresh function I can use ?
I would really like some suggestions ;)
thnx all for reading
If when you h it the back button you are coming back to another viewController i would suggest looking at the method viewWillAppear from UIViewController, you can override this method and call it before you go back, in the method implementation you can set the correct title ...reference http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/viewWillAppear:
How are you inserting the UILabel that you use as a title?
Like this: [self.navigationController.navigationBar.titleView = < label >];
or more like this: [< top window > addSubview: < label >];
I've never had any problems with custom title views using the first method.