3

我有一個實現4個代表一個UIViewController:防止UISearchDisplayController從隱藏導航欄

@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上發現其他問題,但沒有幫助我。

問候

回答

9

我解決使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

+0

這就是我一直在尋找的東西。 – Trent