2
votes

I have two viewControllers ControllerA and ControllerB. Both doesn't have NavigationBar as I have hided the navigationBar in both the controllers. On ControllerB there is a a tableview and on top of that is a searchBar. On selection of any tablerow I am dismissing the controller back to ControllerA. The problem is it shows some Bar on controllerA and I don't know how to hide it.If I don't search anything and Press the back Button on controller B then no navigationBar appears on the ControllerA. But If I select something then it shows. I think its something to do with the searchBar Presentation. Here is my code

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)



    }
1
@user1-add these line in controller B below of self.navigationController!.popViewControllerAnimated(true) self.navigationController?.setNavigationBarHidden(true, animated: true)Devendra Agnihotri

1 Answers

0
votes

You can just use

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