3

编辑添加 *我还没有找到解决这个问题的方法,有人可以帮忙吗?我的问题与此类似,但发布的答案对我不起作用 - MKMapView refresh after pin move *End Edit

我有一个启用搜索的地图视图。当用户点击搜索时,我的自定义注释会添加到地图视图中。搜索返回 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
4

3 回答 3

5

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

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

它的工作!谢谢!

于 2010-11-19T01:07:34.353 回答
1

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

于 2010-04-01T00:22:31.167 回答
0

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

- (void)viewDidLoad
{
    ...

   // map delegate
   [mView setDelegate:self];

   ...

   // add annotation
   [_map addAnnotation:_poiAnnotation];

   ...
}
于 2013-07-10T17:37:18.463 回答