7

Sorry if the title isn't that clear, found it tricky to summarise.

Using Xcode 6 Beta 4, target iOS 8:

I have a UITabBarController and one of its controllers is a UITableViewController (TVC). This TVC has a searchController property which is the new UISearchController which is replacing UISearchDisplayController. Initialising it like so (I would have just added it to my storyboard but the searchController in the object library down in the bottom right is still a UISearchDisplayController - should I file a radar for this?):

self.searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
self.searchController.searchBar.frame = CGRectMake(0, 0, 320, 44);
self.tableView.tableHeaderView = self.searchController.searchBar;

Getting to the point, if the searchBar is first responder:

UISearchController is active and I'm about to choose another tab on the tabBar and come back

and then another tab is selected on the tabBar, and then you come back:

tableView has disappeared

I have no idea why this is happening? UISearchController bug perhaps? Or is the documentation not telling me something that I should be doing (it lacks detail at the moment).

John Topley
  • 113,588
  • 46
  • 195
  • 237
kylejs
  • 1,128
  • 11
  • 25

2 Answers2

5

I got my UISearchController working with no problems on Xcode 6 beta-5 thanks to this sample project I found on GitHub.

Giving credit where credit is due, I think dempseyatgithub has done a fantastic job of making this available for everyone to use as a reference project. Thanks!

fatuhoku
  • 4,815
  • 3
  • 30
  • 70
  • 3
    Brilliant, thank you! That's revealed the issue to me. I had to specify `self.definesPresentationContext = YES;` in my UITableViewController. Although I haven't tried it yet, I assume this will also allow me to specific nil in the init method of the UISearchController (documentation says "Set this to nil to display the search results in the same view that you are searching" for `- (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController`) so that I can use the UITableViewController I am searching as the results TableView. – kylejs Aug 10 '14 at 10:08
  • 1
    Great job, thanks! If you are inside a UINavigationController and a generic UIViewController (with a tableView inside), you should set `self.navigationController!.definesPresentationContext = true`. If you set the property directly on the UIViewController it won't work properly. – maxgallo Feb 12 '15 at 09:45
-1

enter image description here

look at this man , I set this property(definesPresentationContext) to true and it's Solved.

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117