2012-01-20 5 views
3

MKMapViewメソッドsetSelectedを呼び出すと、アノテーションでアニメーションが動作しません。しかし、別の注釈で次回に呼び出すと、作業が始まります。MKMapView setSelected:アニメーション:初めて動作しません。

誰かが間違っている可能性のあるアイデアはありますか? おかげ

コード(2つの関連する方法):

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    annotations = [[NSMutableArray arrayWithCapacity:30] retain]; 
    for (NSDictionary *entry in entries) { 
     double lat = [[entry objectForKey:@"lat"] doubleValue]; 
     double lon = [[entry objectForKey:@"lon"] doubleValue]; 

     NSString *PLZ = [entry objectForKey:@"PLZ"]; 
     NSString *name = [NSString stringWithFormat:@"%@%@", PLZ.length != 0? [NSString stringWithFormat:@"%@, ", PLZ] : @"", [entry objectForKey:@"Ort"]]; 
     NSString *address = [NSString stringWithFormat:@"%@ - %@", [entry objectForKey:@"Grund"], [entry objectForKey:@"Zeit"]]; 

     CLLocationCoordinate2D coordinate; 
     coordinate.latitude = lat; 
     coordinate.longitude = lon;   
     MyLocation *annotation = [[[MyLocation alloc] initWithName:name address:address coordinate:coordinate] autorelease]; 
     [mapView addAnnotation:annotation]; 
     [annotations addObject:annotation]; 
    } 

    NSLog(@"LOaded"); 
    [self zoomToFitMapAnnotations]; 
} 



- (void)showAnnotation:(int)i { 
    if (i <= [annotations count]) { 
     [mapView setSelectedAnnotations:[NSArray arrayWithObject:[annotations objectAtIndex:i]]]; 
    } 
} 

最後の方法は、showAnnotationが呼び出されると、注釈が表示されているものです。もう一度、最初に呼び出すアノテーションでは機能しません。どんなに何度も電話しています。しかし、私が注釈を変更すると、最初に呼び出された注釈があっても作業が開始されます(意味があることを望みます)。

また、これも初めての作品:[mapView setSelectedAnnotations:[NSArray arrayWithObject:[annotations objectAtIndex:i]]];

+0

setSelected:animated:任意のmapViewデリゲート内から呼び出すことができますか? – samfisher

+0

あなたのコードを入れて...どこが間違っているのかわかりますか? –

+0

質問を確認してください。関連するコードを貼り付けた – 0xSina

答えて

1

を使用し、これはあなたがそのメソッドyouself呼び出すべきではありませんあなた

[mapView1 setSelectedAnnotations:[NSArray arrayWithObjects:addAnnotation,nil]]; 
+0

これは動作しますが、アニメーション化されていません:( – 0xSina

+0

[mapView1 selectAnnotation:addAnnotation animated:YES]; これは動作している可能性があります –

2

を助けることができます。 MKAnnotationViewドキュメントによると

:あなたはこのメソッドを直接呼び出すべきではありません

。 MKMapViewオブジェクトは、アノテーションとのユーザーのやり取りに応答して メソッドを呼び出します。

代わりにDipenの推奨方法(setSelectedAnnotations)を試してください。

関連する問題