2
我添加了一個UISearchBar到我最初的UIViewController,並且一切正常。但是,當我添加相同的UISearchBar時,與第一個ViewController的另一個ViewController相同,當我單擊進入searchBar時,似乎沒有任何事情發生。沒有委託方法被激發,沒有鍵盤出現,什麼都沒有。當我點擊NavigationBar中的UISearchBar時,什麼也沒有發生
這是我如何將它添加到的導航欄:
- (void)viewDidLoad {
[super viewDidLoad];
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;
self.searchResults = [NSMutableArray array];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.placeholder = NSLocalizedString(@"Search, eh?", nil);
// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;
self.definesPresentationContext = YES;
}
就像我說的它工作在第一UIViewController中,我失去了在其他2-3 viewControllers事情我已經嘗試添加該太?我不明白爲什麼searchBar會顯示在navBar中,但點擊它後沒有任何事情發生。當你提出一個新的一個儘快
@interface ViewController() <UISearchResultsUpdating>
現在很好用。我想我只需要熟悉一下definePresentationContext,因爲我仍然對這一行實際上做了些什麼感到困惑。似乎searchBar是唯一沒有在其他視圖上工作的東西,但其他一切似乎都正常工作。 – Kimberly