开发者

Iphone Drag'n'Drop MapKit generates "unrecognized selector sent to instance" exception

开发者 https://www.devze.com 2023-01-08 15:24 出处:网络
Recently downloaded \"MapKitDragAndDrop 3\" package (http://github.com/digdog/MapKitDragAndDrop) to use in my app. The demo project runs smoothly.

Recently downloaded "MapKitDragAndDrop 3" package (http://github.com/digdog/MapKitDragAndDrop) to use in my app. The demo project runs smoothly.

Both DDAnnotation.h+m and DDAnnotationView.h+m files were imported as they are. The method of calling the class was also copied/pasted.

DDAnnotation *annotation = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease];
annotation.title = @"Drag to Move Pin";
annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude];

[self.mapView addAnnotation:annotation];

The first run resulted in "unrecognized selector sent to instance" exception. Debugger suggests that I implement setCoordinate methods in DDAnnotation class; yet the demo files has neither @synthesize nor methods implementation.

开发者_JAVA百科

DDAnnotation.m:

#import "DDAnnotation.h"
@implementation DDAnnotation

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary {

if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary])) {
    // NOTE: self.coordinate is now different from super.coordinate, since we re-declare this property in header, 
    // self.coordinate and super.coordinate don't share same ivar anymore.
    self.coordinate = coordinate; // CHECKPOINT
}
return self;
}

@end 

Upon tracing the DDAnnotation.m it falls into DDAnnotation.h on CHECKPOINT in debugger. In my app, it doesn't.

I really expect the mistake to be stupid, yet I just don't know where to look. Thanks.


There's a comment about just this issue in the DDAnnotation.h file.

// NOTE: Since @synthesize by default is done by the LLVM 1.5 compiler (with // flag -Xclang and -fobjc-nonfragile-abi2), we don't need to create method // -setCoordinate: and its ivar anymore. Check out WWDC 2010 Videos, Session // 144 - "Advanced Objective-C and Garbage Collection Techniques", for more // details.


Just like pete said, you need to change some settings in your project file:

  • C/C++ Compiler Version (GCC_VERSION) set to "LLVM compiler 1.5"
  • Other C Flags (OTHER_CFLAGS) should add "-Xclang -fobjc-nonfragile-abi2" flags.

Cause the project is using synthesized property that introduced in LLVM, and the GCC compiler does not support it.

0

精彩评论

暂无评论...
验证码 换一张
取 消