我对 XCode 和 iPhone 开发非常陌生,所以如果这个问题太简单,请多多包涵。但是我有一张地图,并且我已经成功地为我的注释添加了图像(不是图钉)。当用户选择其中一个注释时,我可以更改图像。
我使用以下方法创建了一个继承自 MKAnnotationView 的类:-
- (id)initWithAnnotation:
- (void)setAnnotation:
- (void)drawRect:
我正在使用
- (void)touchesBegan
知道何时选择了注释。在 touchesBegan 中,我正在做:-
UIImage *i = [UIImage imageNamed:@"A.png"];
self.image = i;
更改图像。但我真正难过的是,当用户选择下一个注释时,如何将图像改回原始图像。我努力了:-
NSArray *selectedAnnotations = map.selectedAnnotations;
for(id annotationView in selectedAnnotations) {
[map deselectAnnotation:[annotationView annotation] animated:NO];
}
但它错误
我试过了
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;
}
}
}
上面的代码可以正常工作,直到我到达 ann.image = i; 然后它会出错。我得到的错误是: -
*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[Place setImage:]: unrecognized selector sent to instance 0x4514370'
是的,我可以看到我的地点对象没有图像,这就是它出错的原因。但是,如果我在我的地点对象上创建一个图像属性 - 那将如何改变我正在尝试做的注释图像。
请告知,因为我已经在这个圈子里转了 2 天了!!!!
在此先感谢谢丽尔