0
此代码来自MapCallouts演示。假设我有数百个不同的注释。苹果公司做到这一点,会导致很多代码重复。更简单的方法来编码多个MKAnnotations?
我想访问触发委托的类的实例的注释属性,而不管哪个类实例触发它。
是否有比编写if语句处理每个注释并拥有一个通用方法更简单的方法?
- (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:[BridgeAnnotation class]]) // for Golden Gate Bridge
{
//do something
}
else if ([annotation isKindOfClass:[SFAnnotation class]]) // for City of San Francisco
{
//do something
}
return nil;
}