這是我的第一個關於堆棧溢出的問題,也是我的新iOS開發。 我正在爲我的學校開發地圖應用程序。我的學校有25座建築。我的地圖中有25個MKPinAnnotationViews。如何在MKPinAnnotationView中實現多個標註
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// handle our two custom annotations
//
if ([annotation isKindOfClass:[SchureAnnotation class]]) // for Harry Schure Hall
{
// try to dequeue an existing pin view first
static NSString* SchureAnnotationIdentifier = @"schureAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:SchureAnnotationIdentifier];
if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:SchureAnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
// add a detail disclosure button to the callout which will open a new view controller page
//
// note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement:
// - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
//
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
else if ([annotation isKindOfClass:[SaltenAnnotation class]]) // for Salten Hall
{
// try to dequeue an existing pin view first
static NSString* SaltenAnnotationIdentifier = @"saltenAnnotationIdentifier";
MKPinAnnotationView* pinView = (MKPinAnnotationView *)
[mapView dequeueReusableAnnotationViewWithIdentifier:SaltenAnnotationIdentifier];
if (!pinView)
{
// if an existing pin view was not available, create one
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:SaltenAnnotationIdentifier] autorelease];
..........
我想放一個不同的標註來顯示其每個引腳的信息。我打電話的功能showDetails:它看起來像這樣
- (void)showDetails:(id)sender
{
// the detail view does not want a toolbar so hide it
[self.navigationController setToolbarHidden:YES animated:NO];
[self.navigationController pushViewController:detailViewController animated:YES];
}
中序顯示每個建築物的信息,我需要寫25個視圖控制器?或者有無法使用一個視圖控制器?如果我點擊註解視圖的右鍵,它必須顯示它的信息(圖片,文字)。如果我點擊另一個註釋,它必須通過替換舊信息來顯示其信息。
任何幫助非常感謝。 謝謝, Pradeep。