MKMapView - 加载更多结果时未调用 viewForAnnotation

发布于 2024-08-26 07:12:19 字数 1384 浏览 3 评论 0原文

编辑添加 * 我还没有找到这个问题的解决方案,有人可以帮忙吗?我的问题与此类似,但发布的答案对我不起作用 - MKMapView 在 pin 后刷新移动 *结束编辑

我有一个启用搜索的地图视图。当用户点击搜索时,我的自定义注释将添加到地图视图中。搜索返回 20 个带有“加载更多”链接的结果。当我点击加载更多时,应该将更多注释添加到地图视图中。

问题是 - 注释被添加到地图视图中,但没有显示在地图上。如果我放大或缩小以更改地图区域,则会显示图钉。

我发现当我点击“加载更多”时, viewForAnnotations: 没有被调用。我不知道如何触发这个。任何一个吗?

-(void)completedSearch:(NSNotification *)resultNotification
 {
   //begin loop
   //get coordinate
   customAnnotation *annot = [[customAnnotation alloc] initWithCoordinate: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

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] initWithCoordinate: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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

百思不得你姐 2024-09-02 07:12:19

只是想确认
我正在从线程添加注释 - 这不起作用。
一旦我使用了这个(addCameraIconOnMain 添加了我的注释),

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

它就起作用了!谢谢!

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!

脸赞 2024-09-02 07:12:19

这与接收通知然后添加注释引脚的时间间隔有关。强制它使用主线程添加注释引脚是有效的。

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.

欢烬 2024-09-02 07:12:19

就我而言,问题是我在地图委托之前添加注释。它一定是这样的:

- (void)viewDidLoad
{
    ...

   // map delegate
   [mView setDelegate:self];

   ...

   // add annotation
   [_map addAnnotation:_poiAnnotation];

   ...
}

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];

   ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文