我有一个UIViewController,它将另一个UIViewController表示为UISearchResultsController。
我希望这个searchResultsController在搜索时显示GooglePlaces。
我正在控制台中打印出所有的自动完成预测,但是UITableView没有加载数据。
这是我的功能;
func updateSearchResults(for searchController: UISearchController) {
searchController.searchResultsUpdater = self
if searchController.isActive {
searchController.searchResultsController?.view.isHidden = false
}
if searchController.searchBar.text == "" {
self.searchResults.removeAll()
} else {
guard let query = searchController.searchBar.text else { return }
GMSPlacesClient.shared().autocompleteQuery(query, bounds: nil, filter: filteredResults) { (predictions, error) in
if error != nil {
print(error as Any)
return
} else {
guard let searchPredictions = predictions else { return }
self.searchResults = searchPredictions
print("PREDICTION: \(searchPredictions)")
DispatchQueue.main.async {
self.resultsTableView.reloadData()
}
}
}
}
}卫生检查
1和2设置为self。
3是印刷;
GMSAutocompletePrediction 0x6000037f0450: "England Street, Charlotte, NC, USA", id: EiJFbmdsYW5kIFN0cmVldCwgQ2hhcmxvdHRlLCBOQywgVVNB, types: (
route,
geocode4是给我正确的预测量
我是遵循自定义实现从谷歌这里;
在“以编程方式获得位置预测”下
任何帮助都会被感激。
更新: TableView方法
extension SearchResultsController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchResults.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let resultsCell = resultsTableView.dequeueReusableCell(withIdentifier: resultsCellIdentifier, for: indexPath) as! ResultsCell
let resultsAttributedFullText = searchResults[indexPath.row].attributedFullText.string
resultsCell.textLabel?.text = resultsAttributedFullText
return resultsCell
}更新: cellForRowAt
进一步检查我的cellForRowAt功能;
let results = searchResults[indexPath.row].placeID将results打印到控制台不会给我任何输出。
更新:
在self.searchResults = searchPredictions添加断点结果

更新:
在控制台中,我得到了以下错误;
[BoringSSL] nw_protocol_boringssl_get_output_frames(1300) [C3.1:2][0x7ffd627057e0] get output frames failed, state 8196不确定这是否与我的问题有关,但还是注意到了这一点。
发布于 2018-07-24 14:09:54
请将以下内容替换如下:
DispatchQueue.main.async {
self.resultsTableView.reloadData()
}至
DispatchQueue.main.async {
searchController.searchResultsController.resultsTableView.reloadData()
}https://stackoverflow.com/questions/51500589
复制相似问题