swift – 如何在Google Place AutocompleteViewController中的GMSAutocompleteViewController中设置文本

swift – 如何在Google Place AutocompleteViewController中的GMSAutocompleteViewController中设置文本,第1张

概述在我的应用程序中打开时,我需要帮助在GMSAutocompleteViewController的searchBar中设置文本.我在 Google Place AutocompleteViewController使用GMSAutocompleteViewController. 我通过结合@Youngjin和@ Exception的Swift 4和Google Places 2.6.0的答案得到了一个 在我的应用程序中打开时,我需要帮助在GMSautocompleteVIEwController的searchbar中设置文本.我在 Google Place AutocompleteViewController使用GMSautocompleteVIEwController.

我通过结合@Youngjin和@ Exception的Swift 4和Google Places 2.6.0的答案得到了一个有效的解决方案

要访问GMSautocompleteVIEwController搜索栏:

let vIEws = gmsautoCompleteVIEwController.vIEw.subvIEwslet subvIEwsOfSubvIEw = vIEws.first!.subvIEwslet subOfNavTransitionVIEw = subvIEwsOfSubvIEw[1].subvIEwslet 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的完成块中,它可以正常工作.

将它们组合在一起:

let gmsautoCompleteVIEwController = GMSautocompleteVIEwController()gmsautoCompleteVIEwController.delegate = selfpresent(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中设置文本全部内容,希望文章能够帮你解决swift – 如何在Google Place AutocompleteViewController中的GMSAutocompleteViewController中设置文本所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1033451.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存