ios - 如何确定搜索栏的位置

标签 ios swift

我正在尝试使用https://www.thorntech.com/2016/01/how-to-search-for-location-using-apples-mapkit/的教程来构建搜索功能
我需要更改他的代码
因为从图片中可以看到,如果我执行navigationitem.titleview,加号按钮就会消失。我想在搜索时使用搜索栏,但找不到方法

 let searchBar = resultSearchController!.searchBar
        searchBar.sizeToFit()
        searchBar.placeholder = "Search for places"
        navigationItem.titleView = resultSearchController?.searchBar
        resultSearchController?.hidesNavigationBarDuringPresentation = false
        resultSearchController?.dimsBackgroundDuringPresentation = true
        definesPresentationContext = true
        locationSearchTable.mapView = mapView
        locationSearchTable.handleMapSearchDelegate = self
enter image description here

最佳答案

代替

navigationItem.titleView = resultSearchController?.searchBar
尝试
navigationItem.searchController = resultSearchController

关于ios - 如何确定搜索栏的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63322673/

相关文章:

ios - 在我的项目中使用 API 调用时如何使用自定义事件指示器 View

ios - 上传成功后,构建在 iTunes 连接中不可见

iphone - 我可以在后台状态下查看iPhone的电池状态吗?

html - WebView 插入本 map 片到html 无法成功?

swift - 参数类型 'T.Type' 不符合预期类型 'Comparable'

ios - 如何仅为 64 位 iOS 设备提交存档?

ios - 使用 UserDefaults 终止时保留应用程序

ios - 如何快速更改 UIbutton 的左半径

ios - 快速加载两个 Collection View 和一个 TableView 的核心数据

ios - Swift 4 中 3 个线程的同步