搜索栏在点击后消失 [英] Search Bar disappears after tap on it

查看:157
本文介绍了搜索栏在点击后消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用谷歌地图实现搜索附近的地方。下面是我到目前为止所做的代码

Am trying to implement search nearby places using google maps. The below is the code what I have done so far

 override func viewDidLoad() {
    super.viewDidLoad()
//Adding Mapview
    mapView  = GMSMapView(frame: CGRectMake(0, 120, self.view.bounds.width, self.view.bounds.height - 120))

    self.view.addSubview(mapView)
    mapView.mapType = kGMSTypeNormal

    locationManager.delegate = self
    locationManager.requestWhenInUseAuthorization()

    let resultTableView = UITableView(frame: CGRectMake(10, 100, 300, 60))
    self.searchResultController = UITableViewController()
    self.searchResultController?.tableView = resultTableView
    self.searchResultController?.tableView.dataSource = self
    self.searchResultController?.tableView.delegate = self

      self.searchResultController?.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.searchController = UISearchController(searchResultsController: self.searchResultController)
    self.searchController?.searchResultsUpdater = self
    self.searchController?.hidesNavigationBarDuringPresentation = true
    self.searchController?.dimsBackgroundDuringPresentation = false
    self.searchController?.delegate = self
    self.searchController?.searchBar.frame = CGRectMake(0,70,self.view.bounds.width,40)
    self.searchController?.searchBar.placeholder = "Please choose a location"
    self.view.addSubview(self.searchController!.searchBar)
    self.definesPresentationContext = true
}

一切正常,除了searcg bar单击后消失。但是它有它的功能。

Everything works fine, except searcg bar disappears after a single tap. But it does its function.

推荐答案

我找到了上述问题的解决方案。

I found the solution for my above problem.

func willPresentSearchController(searchController: UISearchController){

    self.searchResultController?.tableView.addSubview(self.searchController!.searchBar)
}

希望对别人有帮助!!!

Hope it helps to others!!!

这篇关于搜索栏在点击后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆