Uisearchdisplaycontroller Without Dimming

UISearchDisplayController Without Dimming?

You are correct that it is the UISearchDisplayController that is managing the "dimming" effect that you're seeing.

What the UISearchDisplayController is doing is adding a UIControl as a subview to the view of the searchContentsController (a property of UISearchDisplayController), which is likely your detail-view controller. This UIControl is just an alpha'd view with a gray background. It seems to have a touch-up-inside event handler that ends searching when tapped.

To constrain the dimming effect to your sub-view of the detail-view, you need to do three things. (I'm assuming your detail-view-controller is defined via a xib. If not, these steps can be done in code too.)

1) add a new UIViewController to your detail-view-controller xib. Attach this new view-controller to an IBOutlet of your detail-view-controller. In my example I call this "_searchAreaViewController". This is important, even if you wont ever access the view controller (but remember, you'll have to release it at some point)

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDelegate, UITableViewDataSource> {

UIPopoverController *popoverController;
UIToolbar *toolbar;

id detailItem;
UILabel *detailDescriptionLabel;

IBOutlet UIViewController* _searchAreaViewController;
}

2) make the containing view for your search area the view of this new view-controller. To do this, use Interface Builder to set a new referencing outlet for this view by dragging the outlet to the searchAreaViewController and selecting the "view" outlet. You must have a containing view - it should be a subview of your detail-view, and it should contain the UISearchBar and likely your UITableView.

3) make the searchContentsController property of the UISearchDisplayController refer to this new view controller instead of the detail-view-controller. This can only be done via Interface Builder as the property is read-only (IB has some magic to make this work?) If you need to do this step via code you'll have to subclass the UISearchDisplayController and return the correct value from a property override of "searchContentsController".

I made a sample app to demonstrate this and the only line of code I had to add to the SplitView template was the one listed in step 1 above. Everything else was just adding the views/controllers and connecting them properly in IB.

good luck!

UISearchDisplayController without instant search: How do I control the dimming of the TableView?

The searchDisplayController is a black box so you don't have any control over when it displays the searchResultsTableView (which in on first key press in the searchBar).

You could display a translucent view over the resultsTableView to give the appearance of the initial dimming provided by the searchDisplayController but the searchResultsTableView will still be visible.

- (BOOL)searchDisplayController:(UISearchDisplayController*)controller
shouldReloadTableForSearchString:(NSString*)searchString
{
// display a translucent view over the searchResultsTableView and
// make sure it's only created on first key press
return NO;
}

The other option is to code your own.

UISearchDisplayController frame for UITableView in iOS

I answered my own question. The frame needs to be set in this delegate method:

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView  {

tableView.frame = self.myTable.frame;

}

Prevent a UISearchDisplayController from hiding the navigation bar

The new UISearchController class introduced with iOS 8 has a property hidesNavigationBarDuringPresentation which you can set to false if you want to keep the navigation bar visible (by default it will still be hidden).

Strange UISearchDisplayController view offset behavior in iOS 7 when embedded in navigation bar

I remember running into the same exact problem that you are observing.There could be a couple of solutions you can try.

  • If you are using storyboards
    You should click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.

  • If you are not using storyboards you can manually set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick. I was using storyboards.



Related Topics



Leave a reply



Submit