1

我有两个viewControllers ControllerA和ControllerB。两者都没有NavigationBar,因为我在两个控制器中隐藏了navigationBar。在ControllerB上有一个tableview,最重要的是一个searchBar。在选择任何表格时,我将控制器退回ControllerA。问题是它在控制器A上显示了一些条,我不知道如何隐藏它。如果我不搜索任何东西,并按下控制器B上的后退按钮,则控制器A上不会出现导航条。但是,如果我选择了一些东西,那么它显示我认为它与searchBar演示文稿有关。这里是我的代码如何隐藏searchController后解除导航栏

ControllerB

override func viewDidLoad() { 
     super.viewDidLoad() 

     self.resultSearchController = ({ 

      let controller = UISearchController(searchResultsController: nil) 
      controller.searchResultsUpdater = self 
      controller.dimsBackgroundDuringPresentation = false 

      controller.searchBar.sizeToFit() 
      controller.searchBar.placeholder = "Search City" 
      self.tableView.tableHeaderView = controller.searchBar 
      self.definesPresentationContext = true 
      return controller 


     })() 

     self.tableView.reloadData() 
    } 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     if (self.resultSearchController.active) { 

      return self.filteredKeys.count 
     } else { 

      return dict.count-1 
     } 

    } 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CountryTableViewCell 

     if(self.resultSearchController.active){ 

      // let key = self.filteredKeys[indexPath.row] 

      //let dictionary = self.dict[key] as! NSDictionary 






       let cityName = (((self.dict["\(indexPath.row)"] as?NSDictionary)!["Country"] as?NSDictionary)!["city_name"] as?NSString) 

       let stateName = (((self.dict["\(indexPath.row)"] as?NSDictionary)!["Country"] as? NSDictionary)!["state_name"] as? NSString) 

       let shortName = (((self.dict["\(indexPath.row)"] as?NSDictionary)!["Country"] as? NSDictionary)!["short_country_name"] as? NSString) 


      if (cityName !== "-" || shortName !== "-"){ 
       cell.stateNameLabel.text = stateName as? String 
       cell.cityNameLabel.text = cityName as? String 
       cell.shortNameLabel.text = shortName as? String 

      } 



     } 
      return cell 


    } 

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     let id = Int((((dict["\(indexPath.item)"] as?NSDictionary)!["Country"] as?NSDictionary)!["id"] as?NSString)! as String) 

     let cityName = (((dict["\(indexPath.item)"] as?NSDictionary)!["Country"] as?NSDictionary)!["city_name"] as?NSString)! as String 

     let countryShortName = (((dict["\(indexPath.item)"] as?NSDictionary)!["Country"] as?NSDictionary)!["short_country_name"] as?NSString)! as String 

     delegate.country(id!,cityName: cityName, countryShortName: countryShortName,departureOrArrivalSegue: departureOrArrivalSegue!) 


     self.navigationController!.popViewControllerAnimated(true) 



    } 
+0

@在控制器B以下 self.navigationController的USER1,添加这些线!.popViewControllerAnimated(真) self.navigationController?.setNavigationBarHidden(true,animated:true) –

回答

0

你可以使用

self.navigationController?.setNavigationBarHidden(true, animated: true)