显示两个不同的注释图像
Displaying two different annotation images
我想显示基于特定 'chain' 变量的 2 种不同类型的注释...我该怎么做呢?这是我现在的代码片段:
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:PharmacyPinID];
NSString *chainString = tmpAnnotation.chain;
NSString *mapImage = [NSString stringWithFormat:@"map_icon_%@",chainString];
pinView.image = [UIImage imageNamed:mapImage];
谢谢!
现在您正在使用通用 MKAnnotationView 对象。你想做些什么不同的事情?
一个简短的回答是做这样的事情:
MKAnnotationView *myAnnotationView;
switch tmpAnnotation.type
{
case type1:
myAnnotationView= [[CustomAnnoation1 alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier: type1ID];
case type2:
myAnnotationView= [[CustomAnnoation2 alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier: type2ID];
default:
myAnnotationView= [[MKAnnotationView alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier:PharmacyPinID];
}
NSString *chainString = tmpAnnotation.chain;
NSString *mapImage = [NSString stringWithFormat:@"map_icon_%@",chainString];
pinView.image = [UIImage imageNamed:mapImage];
上面的代码假设 tmpAnnotation 是一个自定义类型,它有一个 属性 类型,告诉您您想要什么样的注释视图。 (注释是您想要的任何符合 MKAnnotation 协议的对象,因此如果您愿意,它可以具有自定义属性。)
它还假设您有几个不同的 MKAnnotationView 自定义子类要使用。
我想显示基于特定 'chain' 变量的 2 种不同类型的注释...我该怎么做呢?这是我现在的代码片段:
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:PharmacyPinID];
NSString *chainString = tmpAnnotation.chain;
NSString *mapImage = [NSString stringWithFormat:@"map_icon_%@",chainString];
pinView.image = [UIImage imageNamed:mapImage];
谢谢!
现在您正在使用通用 MKAnnotationView 对象。你想做些什么不同的事情?
一个简短的回答是做这样的事情:
MKAnnotationView *myAnnotationView;
switch tmpAnnotation.type
{
case type1:
myAnnotationView= [[CustomAnnoation1 alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier: type1ID];
case type2:
myAnnotationView= [[CustomAnnoation2 alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier: type2ID];
default:
myAnnotationView= [[MKAnnotationView alloc] initWithAnnotation:tmpAnnotation
reuseIdentifier:PharmacyPinID];
}
NSString *chainString = tmpAnnotation.chain;
NSString *mapImage = [NSString stringWithFormat:@"map_icon_%@",chainString];
pinView.image = [UIImage imageNamed:mapImage];
上面的代码假设 tmpAnnotation 是一个自定义类型,它有一个 属性 类型,告诉您您想要什么样的注释视图。 (注释是您想要的任何符合 MKAnnotation 协议的对象,因此如果您愿意,它可以具有自定义属性。)
它还假设您有几个不同的 MKAnnotationView 自定义子类要使用。