I'm building an iOS app and I'm creating a custom UIView
which contains UIWebView
some UIButton
and I'm trying to add UISearchController
the problem is that the view doesn't have UINavigationController
so I created one and I tried to put my UISearchBar
into titleView but it doesn't work .
Here is my code, any idea please !!
- (void)initView {
self.navigationController = [[UINavigationController alloc] init];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed:@"bakground1"]init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.tintColor = [UIColor hx_colorWithHexRGBAString:@"#332532"];
[self initializeSearchController];
self.webView = [[MapWebView alloc] initWithFrame:CGRectMake(0, 100, widthtScreen, heightScreen)];
self.webView.mapWebViewDelegate = self;
[self addSubview:self.webView];
}
- (void)initializeSearchController {
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
searchResultsController.tableView.dataSource = self;
searchResultsController.tableView.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.navigationController.definesPresentationContext = YES;
self.searchController.hidesNavigationBarDuringPresentation = false;
self.searchController.accessibilityElementsHidden= true;
self.searchController.dimsBackgroundDuringPresentation = true;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.navigationController.navigationItem.titleView = self.searchController.searchBar;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
}