Search code examples
iosswiftuitableviewmkmapviewmkannotation

MKPointAnnotation flickers on mapView when on UITableViewCell. How to stop it?


I have a mapView on a UITableViewCell, when I display the mapView, the annotation flickers on and off. Im not sure how to make it stop.

I set up the mapView via

if let event = event {
            mapView.showsUserLocation = true
            mapView.isUserInteractionEnabled = true

            let center = CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude)
            //Create annotation
            let annotation = MKPointAnnotation()
            annotation.coordinate = center
            mapView.addAnnotation(annotation)

            let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005))

            mapView.setRegion(region, animated: true)
        }

I have made sure the annotation is only added to the map once. Here is a video of it happening https://youtu.be/lkpn9Rqd0AE Also, this only happens while there is no user interaction, if I scroll it stops doing it, also if I interact with the map it quits flickering.

I created a test project and it does not have this problem, even though I copied and pasted the above code. Im clueless to whats different.


Solution

  • After contacting apple developer support, they told me that this was a bug not caused by my code.

    Apple has said to remove and add decencies to find which breaks it, OR use the newest version of Xcode in which they fixed the bug. Downloading the newest version of Xcode solved my problem.