【问题标题】:MapView Drop and Drag Pin - Custom MKAnnotationView iOS 5MapView Drop and Drag Pin - 自定义 MKAnnotationView iOS 5
【发布时间】:2011-10-19 18:45:52
【问题描述】:

我一直在寻找几个小时,试图获取和更新一些在 iOS 5 上工作的拖放图钉。我想我已经很接近了……但是在尝试初始化自定义注释时存货。

这是我的课

.h
@interface AnnotationView : MKAnnotationView ...

.m
@interface AnnotationView () 
@property (nonatomic, assign) BOOL hasBuiltInDraggingSupport;
@end

@implementation AnnotationView
@synthesize hasBuiltInDraggingSupport, mapView;


- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {

self.hasBuiltInDraggingSupport = [[MKAnnotationView class] instancesRespondToSelector:NSSelectorFromString(@"isDraggable")];

if (self.hasBuiltInDraggingSupport) {
    if ((self = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier])) {
        [self performSelector:NSSelectorFromString(@"setDraggable:") withObject:[NSNumber numberWithBool:YES]];
    }
}

self.canShowCallout = YES;
return self;
}
@end

而问题就出在了

self = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]

它说:不兼容的指针类型从 'MKPinAnnotationView *' 分配给 'AnnotationView * __strong'

另外,下一行收到警告

[self performSelector:NSSelectorFromString(@"setDraggable:") withObject:[NSNumber numberWithBool:YES]];

谢谢

警告说 setDraggable: 选择器是未知的.. 但不应继承

【问题讨论】:

    标签: iphone mkmapview ios5 mkannotationview mkpinannotationview


    【解决方案1】:
    - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id<MKAnnotation>)annotation
    {
        MKPinAnnotationView* annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"xxx"];
        // check conditions for class of annview or other    
        annView.draggable = YES;
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-23
      • 2011-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 2022-12-02
      • 2020-06-02
      • 1970-01-01
      相关资源
      最近更新 更多