3

Has anyone successfully reloaded a tableView, while the tableView is in the background of a searchbar display controller? See photo with what happens.

I have a UITableViewController with a search display controller. When I call reloadData on UITableViewController's tableview while the search display controller's table view is displayed, the section view header from the UITableViewController gets drawn onto the search display controller's view.

Here is a snapshot that shows the section title view ontop of the search display controller view:

Update: I simplified the code to a simple search display controller and UITableView. If reload data occurs on the tableView with the searchBar active. The issue still happens.

enter image description here

prostock
  • 9,327
  • 19
  • 70
  • 118
  • @titaniumdecoy...added an image. not sure if u seen this before? – prostock Aug 05 '11 at 17:35
  • try to read how to implement them together, you're obviously missing a hint: http://www.edumobile.org/iphone/iphone-programming-tutorials/search-the-content-of-a-uitableview-in-iphone/ – Marek Sebera Aug 06 '11 at 08:56
  • @Marek..I reduced it to the bear minimum with interface builder...i just reload data after the search controller is active to cause the issue – prostock Aug 06 '11 at 18:35
  • Tell me this. Why do you have two different tableviews ? – Legolas Aug 06 '11 at 21:32
  • @legolas. the search display controller holds my search results. the normal table view holds a list of geolocation based results. it's standard for the the search controller to own it's own tableView – prostock Aug 07 '11 at 01:27
  • Not really. I have seen plenty of implementations of searchView where you have just 1 tableView and search for contents inside the tableView, and repopulate the results inside the same tableView. Are you searching for entries in the other table and then displaying it in this table ? – Legolas Aug 07 '11 at 01:31
  • nope.they are two compeletely different data sets. one is a text based search to the database. the other holds geolocation based. you're correct, if i was searching through a single set of data of i could use one table. – prostock Aug 07 '11 at 02:08
  • @prostock: i have the exact same problem as you (which noone else here seems to even understand…) i ended up not calling `reloadData` when my network request completes while the search is active (`view.searchDisplayController.active`) and deferring it to `searchDisplayControllerDidEndSearch:`. very ugly. this has to be a bug in cocoa! –  Aug 07 '14 at 19:33

4 Answers4

1

I hope you know that you need two UITableViews for a search bar to work. When the search is active, you should manage and display the search results table, otherwise your original one.

From Apple's documentation: The results are displayed in a table view that’s created by the search display controller.

Therefore, you should not reload the original UITableView but rather make sure your datasource for the search results table is correct.

UISearchDisplayController has a property called searchResultsTableView which you will not have to specifically reload with reloadData. Rather, it will be updated through the methods in the UISearchDisplayDelegate protocol, such as searchDisplayController:shouldReloadTableForSearchString:.

Cheers,
Sascha

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • @sascha, my other tableView is pretty much independent from the search controllers tableview. its reload is based on the completion of a network request, so can happen while the search display controller is active. if you look at the screenshot, you'll notice the tableview of the search controller delegate is not up...the screen is only blacked out. so i think my problem is really with the search controller being active while the tableview underneath is reloaded. thx – prostock Aug 07 '11 at 22:15
0

I had this exact problem. If your case is like mine, the cause is [self.tableView reloadData] redrawing the self.tableView header title even when self.tableView is below the searchResultsTableView.

[self.tableView reloadData] was being called 1) when I was fetching from my table view data source and 2) in the setter for my fetchedResultsController.

Also, if your tableView controller is a delegate of fetchedResultsController, it receives updates whenever your Core Data managed document is changed. This was also causing the header to be redrawn.

Solution: I removed [self.tableView reloadData] when populating search results. Also, I removed the tableview controller as a delegate of fetchedResultsController.

AVI
  • 9
  • 2
-1

Using NSLog try to check when is your section view header from UITableView gets drawn exactly. May be you can then figure out why this is happening. Then try using scrollEnabled=NO, as you are thinking.

Krishnachandra Sharma
  • 1,332
  • 2
  • 20
  • 42
  • nope..even after i remove scroll enable from the equation..the section header view when reloaded gets loaded ontop of the search view when the search view is active. – prostock Aug 04 '11 at 23:48
-1

You can use simple UISearchBar because without peer into your code, can not help you

Praveen-K
  • 3,401
  • 1
  • 23
  • 31