Skip to main content

Unrecognized selector sent to instance?



I have seen that a few others have had this problem as well. I'm trying to follow a tutorial online that shows how to create animated pins on a MapView.





I have implemented the code as shown in the tutorial and the project builds fine except I receive this exception:







-[MKPointAnnotation iconN]: unrecognized selector sent to instance







I have a subclass of 'MKPinAnnotationView' and in the .m file I create this method:







- (void)setAnnotation:(id<MKAnnotation>)annotation {

[super setAnnotation:annotation];



//Place *place = [[Place alloc] init];

Place *place = (Place *)annotation;





//The following line is where the program sends "SIGABRT"

icon = [UIImage imageNamed:[NSString stringWithFormat:@"pin_%d.png", [place.iconN intValue]]];

[iconView setImage:icon];

}







Here are a few parts from my "model" which is called Place.h/.m. Here is where I create the property for 'iconN'.







@property (retain, nonatomic) NSNumber *iconN;







And here I synthesize it:







@synthesize iconN = _iconN;







Any help is greatly appreciated.





EDIT: Here is the Place.h and Place.m







#import <MapKit/MapKit.h>

#import <CoreLocation/CoreLocation.h>





@interface Place : NSObject <MKAnnotation> {

CLLocationCoordinate2D coordinate;

NSString *title;

}



@property (retain, nonatomic) NSNumber *iconN;

@property (nonatomic, copy) NSString *title;

@property (nonatomic) CLLocationCoordinate2D coordinate;



- (id)initWithLong:(CGFloat)lon Lat:(CGFloat)lat iconNumber:(NSNumber *)iconNumber;



@end







And the Place.m







#import "Place.h"



@implementation Place

@synthesize coordinate;

@synthesize iconN = _iconN;

@synthesize title;



- (id)initWithLong:(CGFloat)lon Lat:(CGFloat)lat iconNumber:(NSNumber *)iconNumber {

self = [super init];

if (self) {

coordinate = CLLocationCoordinate2DMake(lat, lon);

self.iconN = iconNumber;

}



return self;

}



- (NSString *)title {

return [NSString stringWithFormat:@"Bus: %d", [self.iconN intValue]];

}



- (NSString *)subtitle {

return [NSString stringWithFormat:@"bus[%d] from database.", [self.iconN intValue] - 1];

}





@end




Comments

  1. You cannot convert a MKAnnotation to a Place just by casting it. This line is wrong.

    Place *place = (Place *)annotation;


    You should post your Place.h and Place.m files if you're still stuck. You need to either set the iconN property on a new Place object, or create an init method in the Place class that accepts the MKAnnotation object as a parameter and sets it own internal values accordingly.

    ReplyDelete
  2. In the line

    Place *place = (Place *)annotation;


    has the variable place of annotation variable class (MKPointAnnotation), you are not able to bring the master class variable to a subclass in this way. Instead you'll have to make a constructor for Place from MKPointAnnotation and perform a check in the setAnnotation method that annotation is of MKPointAnnotation.

    ReplyDelete
  3. You are sending the message to the annotation but you seem to have subclasses the annotation view.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex