这是我关于堆栈溢出的第一个问题,而且我是新的iOS开发。 我正在为我的学校开发一个地图应用程序。我的学校有25栋楼。我的地图中有25个MKPinAnnotationViews。
- (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个视图控制器?或者有没有使用一个视图控制器?如果我单击注释视图的右键,则必须显示其信息(图片,文本)。如果我点击另一个注释,它必须通过替换旧信息来显示其信息。
任何帮助非常感谢。 谢谢, 普拉迪普。