0

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;
}
Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
  • Please check http://stackoverflow.com/questions/30226835/displaying-search-bar-in-navigation-bar-in-ios-8 and http://stackoverflow.com/questions/5095477/uisearchbar-in-navigationbar – aBilal17 Jun 23 '16 at 06:06
  • No it's not the same case I already did that but now I want to put my uisearchontroller into an uiview not uiviewcontroller –  Jun 23 '16 at 06:09

0 Answers0