3

I have a UIViewController that implements 4 delegates:

@interface AllProductsVC : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate, UISearchDisplayDelegate>{
    NSArray *array;

    NSMutableArray *searchData;
    UISearchBar *searchBar;
    UISearchDisplayController *searchDisplayController;
}
@property int numberOfProducts;
@property int productsToLoad;
@property(nonatomic, retain) UITableView *productsTableView;
@property(nonatomic, retain) UISegmentedControl *segmentedControl;
-(IBAction)getProducts;
@end

My problem is that the viewcontroller has a segmentedControl. During the search if you click the segmentedControl the view doesn't show another time the navigation controller breaking the user interaction with the app.

I tried to hide the segmentedControl during search and only works until you change the segmentControl, if you change it (before searching) after on search is not hidden, i tried the same with enabled but the same result.

Is there any way to don't hide the navigation controller? i tried to search for results and found other questions on stackoverflow but didn't helped to me.

Best regards

Miguel
  • 558
  • 6
  • 21

1 Answers1

9

I solved the problem making the UISearchDisplayController with a custom class:

CustomSearchDisplayController.h

#import <UIKit/UIKit.h>

@interface CustomSearchDisplayController : UISearchDisplayController

@end

CustomSearchDisplayController.m

#import "MySearchDisplayController.h"

@implementation CustomSearchDisplayController
- (void)setActive:(BOOL)visible animated:(BOOL)animated
{
    if(self.active == visible) return;
    [self.searchContentsController.navigationController setNavigationBarHidden:YES animated:NO];
    [super setActive:visible animated:animated];
    [self.searchContentsController.navigationController setNavigationBarHidden:NO animated:NO];
    if (visible) {
        [self.searchBar becomeFirstResponder];
    } else {
        [self.searchBar resignFirstResponder];
    }
}
@end

On the ViewController that I create programmatically the Searchbar first I import the CustomSearchDisplayController.h After I define the searchbar as CustomSearchDisplayController instead of UISearchDisplayController.

Jamie Forrest
  • 10,895
  • 6
  • 51
  • 68
Miguel
  • 558
  • 6
  • 21