0

I had custom MKAnnotationView implemented and it worked correctly before enabling ARC. initWithAnnotation method was implemented like this:

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier 
{
    self.hasBuiltInDraggingSupport = [[MKAnnotationView class] instancesRespondToSelector:NSSelectorFromString(@"isDraggable")];

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

    }
    self.canShowCallout = YES;
    return self;
}

After enabling ARC I started to receive EXC_BAD_ACCESS in the following line:

self = (AnnotationView*)pinAnnView;

Currently i have no idea what happens.

Misha
  • 5,260
  • 6
  • 35
  • 63
  • I took this code from example on how to create custom draggable pin. And it worked fine until i enabled ARC. But after taking some time i solved it by replacing "self = (AnnotationView*)pinAnnView" with "self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifyer]" – Misha Apr 28 '12 at 11:29

1 Answers1

0

The reason is that with ARC the variable is released as soon it comes out of scope and so it never leaves the function. I have the same problem I have not yet found a solution of, though.

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75