iPhone Dev = 地图和取消选择注释
我使用一系列注释成功在地图上绘制注释。我什至可以单击注释并更改其颜色或图像。当用户选择第二个注释并且我想动态地将第一个注释的颜色或图像更改回未选择的颜色/图像时,我的问题出现了。我可以获取所有注释的数组并处理该数组,但是一旦我尝试设置数组的颜色或图像,我就会收到类似的错误。
for (MKAnnotationView *ann in map.selectedAnnotations){
if ([ann isMemberOfClass:[Place class]]) {
place = (Place *)ann;
if (currentPlaceID != place.placeID) {
UIImage *i = [UIImage imageNamed:@"pin.png"];
ann.image = i;
}
}
上面的代码工作正常,直到我到达 ann.image = i;然后就出错了。我得到的错误是:-
- -[Place setImage:]:无法识别的选择器发送到实例 0x4514370 由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'** -[放置 setImage:]: 无法识别的选择器发送到实例 0x4514370'
请告知,因为我已经在这个问题上绕了 2 天了!!!!
关于如何最好地做到这一点有什么想法吗?
提前致谢
I am successfully drawing annotations on a map using an array of annotations. I can even click on the annotation and change it’s colour or image. My problem arises when the use selects the second annotation and I want to dynamically change the colour or image of the first one back to a non-selected colour/image. I can get the array of all the annotations and work through the array but once I try to set the colour or image ot the array I get a similar error.
for (MKAnnotationView *ann in map.selectedAnnotations){
if ([ann isMemberOfClass:[Place class]]) {
place = (Place *)ann;
if (currentPlaceID != place.placeID) {
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'
Please advise as I have been going around in circles on this one for 2 days now!!!!
Any ideas on how best to do this?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你在 Place 类上有一个名为 image 的属性吗?
像...
@property (nonatomic, keep) UIImage* image;
它是否正确合成?@synthesize 图像;
?该错误非常简单,某些对象正在接收一条它不响应的消息,即由 .image 调用的“setImage”。
这是你的代码:
我可以看到:
这意味着什么:
Do you have a property on the class Place called image?
Something like...
@property (nonatomic, retain) UIImage* image;
and is it properly synthesized?@synthesize image;
?The error is pretty straight forward, some object is receiving a message that it doesn't respond to, namely 'setImage' which is invoked by the .image.
Here is your code:
What I can see:
What this means:
我终于想出了如何做到这一点。像往常一样,一旦您知道如何做,这并不难。只是想我会把这个传递下去。
I finally figured out how to do this. As usual it's not that hard once you know how. Just thought I would pass this on.