3

編集して追加*これに対する解決策はまだ見つかりません。誰か助けてもらえますか?私の問題はこれに似ていますが、投稿された回答は私には機能しません-ピンが移動した後のMKMapViewの更新*編集の終了

検索が有効なマップビューがあります。ユーザーが検索を押すと、カスタム注釈がマップビューに追加されます。検索では、「さらに読み込む」リンクを含む20件の結果が返されます。さらに読み込みを押すと、マップビューにさらに注釈を追加する必要があります。

問題は、注釈がマップビューに追加されても、マップに表示されないことです。ズームインまたはズームアウトしてマップ領域を変更すると、ピンが表示されます。

「loadmore」を押しても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 に答える