【问题标题】:Prevent UISearchDisplayController from hiding the navigation bar [duplicate]防止 UISearchDisplayController 隐藏导航栏 [重复]
【发布时间】:2013-05-25 05:39:52
【问题描述】:

我有一个实现 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

我的问题是视图控制器有一个segmentedControl。 在搜索期间,如果您单击 segmentedControl,则视图不会再次显示导航控制器中断用户与应用程序的交互。

我尝试在搜索过程中隐藏 segmentedControl,并且仅在您更改 segmentControl 之前有效,如果您在搜索未隐藏后更改它(在搜索之前),我尝试启用相同但结果相同。

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

最好的问候

【问题讨论】:

    标签: uisearchbar uisegmentedcontrol uisearchdisplaycontroller


    【解决方案1】:

    我解决了使用自定义类制作 UISearchDisplayController 的问题:

    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
    

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

    【讨论】:

    • 这是我一直在寻找的。​​span>
    猜你喜欢
    • 2011-02-18
    • 1970-01-01
    • 2013-12-04
    • 2014-12-05
    • 1970-01-01
    • 2014-10-26
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多