簡體   English   中英

從searchController解散后如何隱藏導航欄

[英]how to hide the navigation bar after dismissing from searchController

我有兩個viewControllers ControllerA和ControllerB。 兩者都沒有NavigationBar,因為我在兩個控制器中都隱藏了navigationBar。 在ControllerB上有一個tableview,最上面是searchBar。 選擇任何表格后,我將控制器退回ControllerA。 問題是它在controllerA上顯示了一些Bar並且我不知道如何隱藏它。如果我什么也沒搜索,然后按控制器B上的向后按鈕,則ControllerA上沒有導航欄出現。 但是,如果我選擇了某項,則會顯示出來。 我認為這與searchBar Presentation有關。 這是我的代碼

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)



    }

你可以使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM