- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在我的应用程序中打开时,我需要帮助在 GMSAutocompleteViewController
的搜索栏中设置文本。我在 Google Place AutocompleteViewController 中使用 GMSAutocompleteViewController
.
最佳答案
通过结合@Youngjin 和@Exception 对 Swift 4 和 Google Places 2.6.0 的回答,我得到了一个可行的解决方案
访问 GMSAutocompleteViewController 搜索栏:
let views = gmsAutoCompleteViewController.view.subviews
let subviewsOfSubview = views.first!.subviews
let subOfNavTransitionView = subviewsOfSubview[1].subviews
let subOfContentView = subOfNavTransitionView[2].subviews
let searchBar = subOfContentView[0] as! UISearchBar
然后设置文本并自动搜索:
searchBar.text = "Your address"
searchBar.delegate?.searchBar?(searchBar, textDidChange: "Your address") // This performs the automatic searching.
我发现在尝试从内部设置文本时收到 EXC_BAD_ACCESS 错误didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController).
所以我改为将这段代码放在我展示 autoCompleteController 的完成 block 中,它可以正常工作。
将它们组合在一起:
let gmsAutoCompleteViewController = GMSAutocompleteViewController()
gmsAutoCompleteViewController.delegate = self
present(gmsAutoCompleteViewController, animated: true) {
let views = gmsAutoCompleteViewController.view.subviews
let subviewsOfSubview = views.first!.subviews
let subOfNavTransitionView = subviewsOfSubview[1].subviews
let subOfContentView = subOfNavTransitionView[2].subviews
let searchBar = subOfContentView[0] as! UISearchBar
searchBar.text = "Your address"
searchBar.delegate?.searchBar?(searchBar, textDidChange: "Your address")
}
编辑:我发现这个解决方案似乎只适用于 iOS 11。让 searchBar = subOfContentView[0] 为! UISearchBar
将在 iOS 10 和可能更低的版本上失败。
关于swift - 如何在 Google Place AutocompleteViewController 的 GMSAutocompleteViewController 中设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381233/
我在我的应用程序中使用 GMSAutocompleteViewController。并且想知道我可以简单地对其进行本地化(搜索栏文本、表格 View 中显示的错误文本等)。 感谢帮助。 最佳答案 你不
我正在使用 Google map 地点选取器并想更改导航栏颜色。我试过以下几行,但他们都在工作......导航栏保持白色...非常感谢您提供的任何帮助! let autocomplet
您好,我使用过 GMSAutocompleteViewController 全屏控件。 https://developers.google.com/places/ios-api/autocomplet
我正在使用 GMSAutocompleteViewController 以便让用户搜索地址。用户选择建议后,如何从 GMSAutocompleteViewController 获取地址详细信息?我正在
我从 添加了自动完成 UI 控件“添加全屏控件” https://developers.google.com/places/ios-api/autocomplete 并使用下面的代码在按下按钮时显示自
当我单击 GMSAutocompleteViewController 时,它应该只显示建议中的所有状态。我不想要这个领域的城市、国家或其他任何东西。那么这可能吗? 最佳答案 您无法直接过滤状态,Goo
这个问题在这里已经有了答案: Change UISearchBar textColor not working (7 个答案) 关闭 3 年前。 我正在使用 GMSAutocompleteViewC
我正在尝试删除 ios 版谷歌地图 API 的 GMSAutocompleteViewController 中的默认“取消”按钮。我该怎么做呢?这可能吗? 在此处输入图像描述 最佳答案 试试这个您可以
我最近将我的应用程序升级到 swift 3,每当它尝试调用谷歌地图中的自动完成 View Controller 时,它就会崩溃。我知道 api key 不是问题,因为在我升级到 swift 3 和 x
我在 iOS 中使用 Google 自动完成 placekicker。它向我展示了具有原生设计的 Controller 。我想自定义它的导航栏颜色。但我做不到。下面是代码 let au
我在我的应用中集成了 GMSAutocompleteViewController。 let autocompleteController = GMSAutocompleteViewController
我正在尝试子类化 GMSAutocompleteViewController 形式 GooglePlaces SDK,如下所示: class AddressFinderViewController:
这是我的 viewController 中的委托(delegate)函数: func viewController(_ viewController: GMSAutocompleteViewContr
我正在为我的应用实现默认的 GMSAutocompleteViewController。但是找不到任何文档或指南来将 searchController 的文本字段中的文本颜色更改为白色。现在看起来是黑
在我的应用程序中打开时,我需要帮助在 GMSAutocompleteViewController 的搜索栏中设置文本。我在 Google Place AutocompleteViewControlle
我是一名优秀的程序员,十分优秀!