ios - Swift 选择 map 图钉并在 tableView Cell 上显示详细信息时如何操作

标签 ios uitableview mapkit

我是 swift 开发人员的新手,我在网上搜索了很长时间。但是没有用。请帮助或尝试提供一些想法如何实现这一目标。

当我选择将在 tableView Cell 上显示详细信息的 map 图钉时,我想做的事情。

喜欢这两张照片

This is photo1

enter image description here

and when I select the image will like photo2. Name,Address,TelNumber Label will show the Detail

enter image description here

and I try to do this code but still didn't work

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"]
}

我该怎么做?有任何想法吗?伙计,干杯!

最佳答案

所有你需要创建一个tableview cell xib和它的类然后你需要使用这个方法来加载那个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 是您的 tableview 单元格 Nib 名称

关于ios - Swift 选择 map 图钉并在 tableView Cell 上显示详细信息时如何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40924485/

相关文章:

ios - 批量删除请求使应用程序崩溃

ios - 黑暗角落 UITableViewController

ios - 重新加载数据后更改 UIButton 文本

ios - 带有 UISearchBar 的奇怪行为 UIRefreshControl

ios - MKMapview 在模拟器的 iOS-7.0 中不显示 map

ios - Pin 无效

ios - 什么是交错音频?

ios - 获取 Facebook 的应用程序链接托管 API

ios - iOS:未呈现NSMutableAttributedString.AddAttributes。 (Xamarin)

swift - 无法等待 MKDirections.calculate 的结果,取而代之的是 nil