阻止UISearchDisplayController隐藏导航栏

Mig*_*uel 3 uisegmentedcontrol uisearchbar uisearchdisplaycontroller

我有一个实现4个委托的UIViewController:

@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
Run Code Online (Sandbox Code Playgroud)

我的问题是viewcontroller有一个segmentedControl.在搜索期间,如果单击segmentedControl,则视图不会显示导航控制器违反用户与应用程序交互的其他时间.

我试图在搜索过程中隐藏segmentedControl,直到你更改了segmentControl,如果你在搜索没有隐藏之后更改它(搜索之前),我尝试了同样的启用但相同的结果.

有没有办法不隐藏导航控制器?我试图搜索结果,并在stackoverflow上找到其他问题,但没有帮助我.

最好的祝福

Mig*_*uel 9

我解决了使用自定义类创建UISearchDisplayController的问题:

CustomSearchDisplayController.h

#import <UIKit/UIKit.h>

@interface CustomSearchDisplayController : UISearchDisplayController

@end
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

在我首先以编程方式创建搜索栏的ViewController上,我导入了CustomSearchDisplayController.h 以后定义搜索栏CustomSearchDisplayController而不是UISearchDisplayController.