Note that there are some explanatory texts on larger screens.

plurals
  1. POMKMapView won't add any annotations
    primarykey
    data
    text
    <p>I have an MKMapView whose delegate is set in Interface Builder and which is a retained property (hooked up in Interface Builder as well) of its view controller. Yes, I am sure they are hooked up properly. I am trying to add annotations to the mapView, but mapView: viewForAnnotation: is not called, and after adding all of the annotations with [self.map addAnnotation:annot], printing the count of the mapView's annotations array yields zero. I have no idea what is causing this because my MapPerson object implements the MKAnnotation protocol with a readonly coordinate property. Here is my code for that business...</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;MapKit/MapKit.h&gt; @interface MapPerson : NSObject &lt;MKAnnotation&gt; { CLLocationCoordinate2D _coo; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; @end </code></pre> <p>And its implementation...</p> <pre><code>#import "MapPerson.h" @implementation MapPerson @synthesize coordinate=_coo; - (id)init { self = [super init]; if (self) { // Initialization code here. } return self; } - (id)initWithCoordinate:(CLLocationCoordinate2D)loc { self = [super init]; if (self) { _coo = loc; } return self; } </code></pre> <p>I am trying to create these annotations in a delegate method from a service class which fetches coordinates from a server to the view controller containing the mapView. I have tried moving that code to a helper method which I make sure to call on the main thread, but nothing happens.</p> <pre><code>- (void)refreshMap { for (MapPerson *p in mapPeople) { [self.map addAnnotation:p]; } NSLog(@"Mapview has %i annotations.", self.map.annotations.count); // is always 1 for the user's location } </code></pre> <p>I have Googled and SO's and looked at several different tutorials which do not differ from my code except in names. I put a breakpoint in mapView: viewForAnnotation:, and it is only called once for the user's location annotation. The count of mapPeople is 5. Their coordinates are being set correctly. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload