【问题标题】:Displaying two different annotation images显示两个不同的注释图像
【发布时间】:2015-05-08 22:56:44
【问题描述】:

我想根据特定的“链”变量显示 2 种不同类型的注释...我该怎么做呢?这是我现在拥有的代码 sn-p:

pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation  
  reuseIdentifier:PharmacyPinID];

NSString *chainString = tmpAnnotation.chain;
NSString *mapImage = [NSString stringWithFormat:@"map_icon_%@",chainString];
pinView.image = [UIImage imageNamed:mapImage];

谢谢!

【问题讨论】:

    标签: ios objective-c annotations mapkit reuseidentifier


    【解决方案1】:

    现在您正在使用通用 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 要使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 2014-10-27
      相关资源
      最近更新 更多