MapView 拖放引脚 - 自定义 MKAnnotationView iOS 5

发布于 2024-12-10 20:00:03 字数 1359 浏览 0 评论 0原文

我花了好几个小时寻找并更新一些可以在 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]

它所说的行上: Incompromedpointers types allocateing to 'AnnotationView * __strong' from 'MKPinAnnotationView *'

另外,下一行收到警告

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

Thx

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

I kept looking for hours, trying to get and update somehting to work on iOS 5 for a drop and drag pin. I think i'm pretty close... but stock when trying to init a custom annotation.

Here's my class

.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

And the problem is on the line

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

it says : Incompatible pointer types assigning to 'AnnotationView * __strong' from 'MKPinAnnotationView *'

Also, the next line is getting a warning to

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

Thx

The warning says that setDraggable: selector is unknow.. but shouldn't be herited from

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2024-12-17 20:00:04
- (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;
}
- (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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文