隐藏地图注释后,Swift 4 mapkit重新加载地图

时间:2018-04-29 21:13:56

标签: swift annotations mapkit

我有两个viewcontrollers,它们显示一个mapkit,另一个用于具有后退按钮的地方描述。但每当我尝试隐藏地图注释并转到地点描述然后再返回到mapkit时,它会重新加载我的地​​图,并使用我试图隐藏的注释。如何阻止mapkit重新加载其数据但仍隐藏我的地图注释?

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        //1
        let coordinate = view.annotation!.coordinate
        //2
        if let userCoordinate = userLocation {
            //3
            if userCoordinate.distance(from: CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude)) < 30000 {
                //4

                let storyboard = UIStoryboard(name: "Main", bundle: nil)

                if let viewController = storyboard.instantiateViewController(withIdentifier: "ARViewController") as?    PlaceViewController {
                    // more code later
                    //5
                    if let mapAnnotation = view.annotation as? MapA {
                        //6
                        if(mapAnnotation.title == "New")
                        {
                         mapView.view(for: mapAnnotation)?.isHidden = true
                            self.present(viewController, animated: true, completion: nil)
                            viewController.adL.text = "TEST"
                       viewController.descT.text = "Hej"



                        }
}

1 个答案:

答案 0 :(得分:0)

重装,因为这里

mapView.view(for: mapAnnotation)?.isHidden = true

您明确地将其称为重新加载

你可以直接做

view.isHidden = true 

当你在这里看到视图时

didSelect view: MKAnnotationView

目前已选中