Ios 从searchController中解除后如何隐藏导航栏

Ios 从searchController中解除后如何隐藏导航栏,ios,swift,uinavigationbar,uisearchcontroller,uisearchresultscontroller,Ios,Swift,Uinavigationbar,Uisearchcontroller,Uisearchresultscontroller,我有两个视图控制器ControllerA和ControllerB。两者都没有导航栏,因为我已将导航栏隐藏在两个控制器中。在ControllerB上有一个表格视图,其顶部是一个搜索栏。在选择任何tablerow时,我会将控制器退回ControllerA。问题是它在controllerA上显示了一些栏,我不知道如何隐藏它。如果我不搜索任何内容并按下控制器B上的后退按钮,则controllerA上不会显示导航栏。但是如果我选择了什么,它就会显示出来。我认为这与搜索栏演示有关。这是我的密码 控制器B o

我有两个视图控制器ControllerA和ControllerB。两者都没有导航栏,因为我已将导航栏隐藏在两个控制器中。在ControllerB上有一个表格视图,其顶部是一个搜索栏。在选择任何tablerow时,我会将控制器退回ControllerA。问题是它在controllerA上显示了一些栏,我不知道如何隐藏它。如果我不搜索任何内容并按下控制器B上的后退按钮,则controllerA上不会显示导航栏。但是如果我选择了什么,它就会显示出来。我认为这与搜索栏演示有关。这是我的密码

控制器B

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)



    }
你可以用

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

@user1在self.navigationController!下面的控制器B中添加这些行!。popViewControllerAnimated(true)self.navigationController?.setNavigationBarHidden(true,动画:true)