简体   繁体   中英

MapView Drop and Drag Pin - Custom MKAnnotationView iOS 5

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

- (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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM