我是swift开发人员的新手,我在网上搜索了很长时间。但没用。请帮助或尝试提供一些如何实现这一目标的想法。
当我选择将在tableView Cell上显示细节的地图图钉时,我想这样做。
喜欢这两张照片
这是photo1
当我选择图像时会喜欢photo2。名称,地址,TelNumber标签将显示详细信息
我试着做这个代码,但仍然没有工作
var dictRow = [String:String]()
var dicRow = [String:[String:String]]()
func getAddPin (){
for index in arrTable{
let Annotation = MKPointAnnotation()
let bLatitude = index["Latitude"] as! Double
let bLongitude = index["Longitude"] as! Double
Annotation.coordinate = CLLocationCoordinate2DMake(bLatitude , bLongitude)
Annotation.title = index["Name"] as? String
//writeing detail which pins is already make in map view
//I try use Annotation for key when I select pin can get value
PinName = [Annotation.title!] //Name for key
dictRow["ClassType"] = index["ClassType"] as? String
dicRow[Annotation.title!] = dictRow //write to dict
dictRow["City"] = index["City"] as? String
dicRow[Annotation.title!] = dictRow
dictRow["Area"] = index["Area"] as? String
dicRow[Annotation.title!] = dictRow
dictRow["Address"] = index["Address"] as? String
dicRow[Annotation.title!] = dictRow
dictRow["TelArea"] = index["TelArea"] as? String
dicRow[Annotation.title!] = dictRow
dictRow["Tel"] = index["Tel"] as? String
dicRow[Annotation.title!] = dictRow
myMapView.addAnnotations([Annotat
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
Pintouch = true
tableView2.isHidden = false
print(Pintouch)
myMapView.frame = CGRect(x: 0, y: 215, width: DeviceWidth, height: DeviceHeight - 330)
self.tableView2.reloadData()
}
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
Pintouch = false
tableView2.isHidden = true
myMapView.frame = CGRect(x: 0, y: 35, width: DeviceWidth, height: DeviceHeight - 150)
}
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath)-> UITableViewCell {
if Pintouch == true {
cell = tableView2.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! ClintTableViewCell
MapPinName = PinName[indexPath.item]
dictRow = dicRow[MapPinName]!
cell.MyCellName.text = MapPinName
cell.MyCellCT.text = dictRow["ClassType"]
cell.MyCellCIty.text = dictRow["City"]
cell.MyCellArea.text = dictRow["Area"]
cell.MyCellAddress.text = dictRow["Address"]
cell.MyCellTelArea.text = dictRow["TelArea"]
cell.MyCellTelArea.text = cell.MyCellTelArea.text! + "-"
cell.MyCellTelNum.text = dictRow["Tel"]
}
我该怎么做?有任何想法吗?欢呼队友!
答案 0 :(得分:1)
All you need to create a tableview cell xib and its class then you need to use this method to load that tableview cell xib -
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
let searchResultDict:SearchResult = self.searchListItems.object(at: index) as! SearchResult
let DetailScreenVC = DetailScreenVC(nibName: "DetailScreenVC", bundle: nil)
ScreenVC.organizationId = searchResultDict.organizationId
ScreenVC.countryId = searchResultDict.countryId
DetailScreenVC.stateId = searchResultDict.stateId
DetailScreenVC.activityId = searchResultDict.activityId
self.navigationController!.pushViewController(DetailScreenVC, animated: true)
}
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let infoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self,options: nil)?.first! as! CustomInfoWindow
infoWindow.label.text = "\(marker.position.latitude) \(marker.position.longitude)"
return infoWindow
}
PS:- DetailScreenVC is your tableview cell nib name