【发布时间】:2017-12-11 04:31:15
【问题描述】:
我在当前项目中使用谷歌地图。要在我单击 textField 时搜索位置,tableView 会出现在下方,并且我正在使用 GMSAutocompletePrediction 对象填充单元格。到目前为止,它工作正常,到目前为止没有问题。现在我想添加一个像“从地图中选择”这样的单元格,当有人点击一个单元格时,地图中就会出现一个标记。我可以放置标记和附加地图功能,但如何添加最后一个单元格“从地图中选择”?我的代码如下:
var myFilterPredictions = [GMSAutocompletePrediction]()
然后:
func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
self.myFilterPredictions.removeAll()
print("GMSAutocompletePrediction *********")
for i in predictions {
self.myFilterPredictions.append(i)
}
tableView.reloadData()
}
填充tableView
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myFilterPredictions.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style:.subtitle, reuseIdentifier:"searchCell")
let predictions = myFilterPredictions[indexPath.row]
cell.textLabel?.attributedText = predictions.attributedPrimaryText
cell.detailTextLabel?.attributedText = predictions.attributedFullText
return cell
}
【问题讨论】:
-
尝试将
footer添加到tableview。此 URL 将有所帮助:stackoverflow.com/questions/38178509/… -
不,那不是我想要的,我想要 tableViewCell
-
你的意思是,你想在tableviewcell中显示地图,对吧?
-
@SagarSukode 不,这不是我想要的,我想添加一个名为“从地图中选择”的单元格,当我点击它时,我将在地图上显示一个标记。我可以显示标记,但我不能将最后一个单元格设置为“从地图中选择”。
-
@ArafinRussell 然后为“从地图中选择”添加一个自定义单元格,并在点击时执行所需的功能(即:didSelectRowAt)。
标签: swift