3

我有一个实现 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 上找到了其他问题,但对我没有帮助。

此致

4

1 回答 1

9

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

CustomSearchDisplayController.h

#import <UIKit/UIKit.h>

@interface CustomSearchDisplayController : UISearchDisplayController

@end

自定义搜索显示控制器.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 上,首先导入 SearchbarCustomSearchDisplayController.h 之后,我将 searchbar 定义为CustomSearchDisplayController而不是UISearchDisplayController.

于 2013-05-30T15:29:25.760 回答