开发者

MKMapView - viewForAnnotation not called while loading more results

开发者 https://www.devze.com 2022-12-23 14:54 出处:网络
Edited to Add * I haven\'t found a solution for this one yet, can anyone please help? My problem is similar to this but the answer posted doesn\'t t work for me - MKMapView refresh after pin moves *En

Edited to Add * I haven't found a solution for this one yet, can anyone please help? My problem is similar to this but the answer posted doesn't t work for me - MKMapView refresh after pin moves *End Edit

I have a search enabled map view. When user hits search, my custom annotations are added to the map view. The search returns 20 results with a 'load more' link. When I hit load more, more annotations should be added to map view.

The problem is - annotations gets added to the map view but is not displayed on the map. If I zoom in or zoom out to change the map region, the pins are shown.

I find that viewForAnnotations: is not getting called when i hit 'load more'. I am not sure how to trigger this. any one?

-(void)completedSearch:(NSNotification *)resultNotification
 {
   //begin loop
   //get coordinate
   customAnnotation *annot = [[customAnnotation alloc] init开发者_开发技巧WithCoordinate:coordinate];
   //set title subtitle 
   [annotationsArray addObject:annot];
   //end loop
   [mView addAnnotations:annotationsArray];
   [mView setRegion:region animated:YES];
   [mView regionThatFits:region];
 }

  //custom annotation
  @interface customAnnotation : NSObject <MKAnnotation> 
 { 
   CLLocationCoordinate2D coordinate;  
   NSString*              title; 
   NSString*              info; 
 } 
 @property (nonatomic, retain) NSSting *title;
 @property (nonatomic, retain) NSSting *info;

 -(id) initWithCoordinate:(CLLocationCoordinate2D)c;
 @end

 @implementation customAnnotation
 @synthesize coordinate, title, info;
 -(id) initWithCoordinate:(CLLocationCoordinate2D)c
 {
   coordinate = c;
   return self;
 }
 -(void)dealloc{//dealloc stuff here}
 @end


just wanted to confirm i was adding annotations from a thread - which doesnt work. once I used this (addCameraIconOnMain adds my annoations)

[self performSelectorOnMainThread:@selector(addCameraIconOnMain:) withObject:cd waitUntilDone:true];    

its worked! thanks!


This had something to do with the time lapse receiving the notification and then adding the annotation pins. Forcing it to use the main thread to add annotation pins worked.


in my case the problem was I was adding the annotation before the map delegate. It must be something like:

- (void)viewDidLoad
{
    ...

   // map delegate
   [mView setDelegate:self];

   ...

   // add annotation
   [_map addAnnotation:_poiAnnotation];

   ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号