0

When i run my app, it crashes and i got this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AnnotationsDisplay coordinate]: unrecognized selector sent to instance 0x795bda0'

AnnotationsDisplay it's a class to manage displaying the PINS on the Map.

EDIT: This is my AnnotationsDisplay class code:

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface AnnotationsDisplay : NSObject<MKAnnotation> {
    NSString *title;
    CLLocationCoordinate2D coordinate;
}
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d;
@end

.m:

#import "AnnotationsDisplay.h"

@implementation AnnotationsDisplay
- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
    title = ttl;
    coordinate = c2d;
    return self;
}
@end
Malloc
  • 15,434
  • 34
  • 105
  • 192

4 Answers4

2
@protocol MKAnnotation <NSObject>

// Center latitude and longitude of the annotion view.
// The implementation of this property must be KVO compliant.
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

@optional

// Title and subtitle for use by selection UI.
@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

// Called as a result of dragging an annotation view.
- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate NS_AVAILABLE(NA, 4_0);

@end

Properties are already declared in MKAnnotation protocol. Just add @synthesize for each property.

Nikita Ivaniushchenko
  • 1,425
  • 11
  • 11
0

Without code it's impossible to tell where exactly your error is, but it looks like you're using your AnnotationDisplay instance in wrong place, and it's attempted to be sent with coordinate message, that is not supported.

Denis
  • 6,313
  • 1
  • 28
  • 27
0

Does your AnnotationsDisplay conforms to MKAnnotation protocol?

Nikita Ivaniushchenko
  • 1,425
  • 11
  • 11
0

An init method should almost always call super.
Here is an exemple for a UITableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
    // Custom initialization

}
return self;
}

since you are subclassing NSObject, there is a lot in the initialization of NSObject that will put your object in a valid state.

And in your code it should be like this

- (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d {
self = [super init];  // init from NSObject
if (self) {
  title = ttl;
  coordinate = c2d;
}
return self;
}
Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40