在我的視圖控制器我編程方式添加一個搜索欄,它似乎正是我想要的方式,但是當我點擊它做什麼我不能寫/類型的東西搜索欄,並且日誌中沒有錯誤。 我添加的搜索欄在其他視圖控制器相同的方式,它的作品,但在那個特定的它不工作。我從前一個視圖控制器推動這個視圖控制器,因此它在左邊有一個導航返回按鈕(檢查圖像)它也可以工作。UISearchController搜索欄顯示,但不工作/觸發
在視圖控制器有一個TableView中和的CollectionView我想添加爲表視圖搜索。我想知道是否有這兩個在同一個視圖控制器中有什麼關係。
代碼中加入搜索欄
- (void)viewDidLoad {
//other stuff on view controller
[self setSearchView];
}
-(void)setSearchView{
//searchController is added as a property on .h file
//and all the delegate are also added
//@property (strong, nonatomic) UISearchController *searchController;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater= self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.navigationController.toolbarHidden=YES;
self.navigationItem.titleView=self.searchController.searchBar;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.definesPresentationContext = YES;
}
我來到這個視圖控制器從以前的視圖控制器,並單擊按鈕時按下此視圖控制器。而我使用榫文件
按鈕動作
- (void)ButtonClicked {
MYNextViewController *nextViewController = [[MYNextViewController alloc] initWithNibName:@"MYNibFileName" bundle:nil];
// I also have a tab bar on the bottom which i am hiding for that view controller when pushing
nextViewController .hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:nextViewController animated:YES];
}
任何幫助將不勝感激。希望我做我自己清楚......
嘗試使用視圖herrachy調試並查看是否有阻止搜索欄或不 – Tj3n
也許有在層次中的問題,我無法找到任何東西。我會看看..tnx –
你有沒有試着去'[_ searchController becomeFirstResponder]''入法searchBarTextDidBeginEditing'呀 – Shahrukh