Hi
I am very new to XCode and iPhone development so please bear with me if this question is too simple. But I have a map and I have successfully added images (not pins) to it for my annotations. And I can change the image when the user selects one of the annotations.
I created a class that inherits from MKAnnotationView with the following methods:-
- (id)initWithAnnotation:
- (void)setAnnotation:
- (void)drawRect:
and I am using
- (void)touchesBegan
to know when an annotation has been selected. And in touchesBegan I am doing :-
UIImage *i = [UIImage imageNamed:@"A.png"];
self.image = i;
to change the image. But what I am really stumped on is how do I change the image back to it's original image when the users selects the next annotation. I have tried:-
NSArray *selectedAnnotations = map.selectedAnnotations;
for(id annotationView in selectedAnnotations) {
[map deselectAnnotation:[annotationView annotation] animated:NO];
}
but it errors
and I tried
for (MKAnnotationView *ann in map.selectedAnnotations){
if ([ann isMemberOfClass:[Place class]])
{
place = (Place *)ann;
NSLog(@"second = %@"@" %f"@" %f", place.title, place.longitude, place.latitude);
if (currentPlaceID == place.placeID) {
//UIImage *i = [UIImage imageNamed:@"A.png"];
//ann.image = i;
}
else {
UIImage *i = [UIImage imageNamed:@"pin.png"];
ann.image = i;
}
}
}
the above code works ok until I get to ann.image = i; then it errors. The errors I get are:-
*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370'
Yes I can see that my place object does not have an image so that's why it is going wrong. But if I create an image property on my place object - how will that change the annotations image which what I am trying to do.
Please advise as I have been going around in circles on this one for 2 days now!!!!
Thanks in advance Cheryl