2012-04-19 10 views
0

私はいくつかの注釈を読み込むマップを持つビューを持っています。すべて正常に機能しますが、注釈を消去して他の注釈を追加する場合は、地図を移動(スクロール)するまで表示されません。マップをスクロールするまで、MKAnnotationsが表示されない

提案がありますか?

EDITED:

ではなく、これを使用してのように思える:

[self updateMap]; 

私が使用する必要があります:

[self performSelectorOnMainThread:@selector(updateMap) withObject:nil waitUntilDone:true]; 

を更新マップ、私は私の新しい注釈を追加する方法であること。このような

答えて

0

試行のなめらか:のviewDidLoadの使用において

[mapView removeAnnotations:[mapView annotations]]; 
NSArray *targetArray = /*YOUR ARRAY NAME with object, containing `latitude`, `longitude` and `title` values*/ 
for (id *item in targetArray) { 
    if (item.latitude && item.longitude) { 
     MKPin *pin = [[MKPin alloc] init]; // MKPin is your class which specifies the deledate `MKAnnotation` 
     pin.coordinate = CLLocationCoordinate2DMake(item.latitude, item.longitude); 
     pin.title = item.title; 
     [mapView addAnnotation:pin]; 
    } 
} 
+0

いいえ、私は各アノテーションのデフォルトビューを使用していますが、 'mapView:viewForAnnotation:'メソッドを呼び出す必要がありますが、マップをスクロールするまで呼び出されません。 – sergiocg90

+0

注釈のデフォルトビューを使用する場合、 'mapView:viewForAnnotation:'メソッドを実装しないでください。また、必要に応じて、このメソッドを手動で実行することもできます。最後の条件ブロックで、これを書いてください: '[self mapView:mapView viewForAnnotation:pin];' – demon9733

0

- (void)viewDidLoad 

{

NSMutableArray* annotations=[[NSMutableArray alloc] init]; 
    MyAnnotation* myAnnotation = [[MyAnnotation alloc] init]; 
myAnnotation.coordinate = theCoordinate; 
    [annotations addObject:myAnnotation]; 
    MKMapRect flyTo = MKMapRectNull; 
for (id <MKAnnotation> annotation in annotations) 
    { 
    NSLog(@"fly to on"); 
     MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate); 
     MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0); 
     if (MKMapRectIsNull(flyTo)) 
     { 
       flyTo = pointRect; 
     } 
     else 
     { 
       flyTo = MKMapRectUnion(flyTo, pointRect); 
     //NSLog(@"else-%@",annotationPoint.x); 
     } 
    } 

// Position the map so that all overlays and annotations are visible on screen. 
mapView.visibleMapRect = flyTo; 

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 

{ NSLog(@ "マップビューアノテーションへようこそ");

// if it's the user location, just return nil. 
if ([annotation isKindOfClass:[MKUserLocation class]]) 
    return nil; 

// try to dequeue an existing pin view first 
static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc] 
           initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease]; 
pinView.animatesDrop=YES; 
pinView.canShowCallout=YES; 
pinView.draggable = NO; 
pinView.pinColor=MKPinAnnotationColorGreen; 

//button on the right for popup for pins 
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
[rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
[rightButton addTarget:self 
       action:@selector(showDetails:) 
     forControlEvents:UIControlEventTouchUpInside]; 
pinView.rightCalloutAccessoryView = rightButton; 

//zoom button on the left of popup for pins 
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeContactAdd]; 
[leftButton setTitle:annotation.title forState:UIControlStateNormal]; 
[leftButton addTarget:self 
       action:@selector(zoomToLocation:) forControlEvents:UIControlEventTouchUpInside]; 
pinView.leftCalloutAccessoryView = leftButton; 

UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]]; 
pinView.leftCalloutAccessoryView = profileIconView; 
[profileIconView release]; 


return pinView; 

}

うまくいけば、これは!!!!!!!!!役立ちます

関連する問題