MKAnnotation not appearing when added

I am successfully adding annotations to an MKMapView in all but one case:


override func Show()

{

fDimmed = !IsVisible(point: coordinate)

var ann = gMapView.annotations

gMapView.addAnnotation(self)

ann = gMapView.annotations

}


The "ann" variable is just debugging to inspect the annotations list before and after the addition and, sure enough, the annotation is added. However, the app returns to user control without ever calling the


mapView(_ mapView: MKMapView, viewFor: MKAnnotation)


function to actually place the annotation view.


The class is declared as


ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {}


and as I said, with several other annotations, it works fine. Any ideas?


Steve.

Replies

You should move your post to Maps and Location section. You'll get better feedback. Good luck.

I should add that the annotation itself is a Lodge, which is declared


class Lodge: Mapsite, NSCoding

{

var fMember = false

var fSaleItem:[Int] = [0,0,0,0]

....

}


class Mapsite: MapObject

{

var fIsLodge = false

var fClues: Int = 0

var fXY: [Int] = [0,0]

var fLocation: [Double] = [0,0]

var fDimmed = true

....

}


class MapObject: NSObject, MKAnnotation

{

var fIsCampfire = false

var fIsExplorer = false

var coordinate = CLLocationCoordinate2D()

var fView: MKAnnotationView?

....

}


The variable required by the protocol (coordinate:CLLocationCoordinate2D) has a non-zero value but that's actually not relevant since, as I said, mapView is not even being called (I've set a breakpoint to verify that). The annotations that work are not Mapsites, they're in other subclasses of MapObject.

I don't understand what you add:

override func Show() {

fDimmed = !IsVisible(point: coordinate)

var ann = gMapView.annotations

gMapView.addAnnotation(self)

ann = gMapView.annotations

}


Syntax is

func addAnnotation(_ annotation: MKAnnotation)

So parameter must be MKAnnotation


Whai is self here ? Is it a new annotation ?


Are you sure that addAnnotation occurs in main thread ?


Please, show the complete code of the class where you define show()


Note: by Swift convention, Show should start with lowercase show