0

我正在尝试向地图添加地标。地标是从完全在通讯簿之外的地址构建的。

我的地标出现在地图上,但是当我尝试捏放大时,我遇到了崩溃:

*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0'

这是我设置地址的方式:

id theAddress = [NSDictionary dictionaryWithObjectsAndKeys:
                 [NSString stringWithFormat: @"%@ - %@", theAddress1 ? theAddress1 : @"", theAddress2 ? theAddress2 : @""], kABPersonAddressStreetKey,
                 theCity ? theCity : @"", kABPersonAddressCityKey,
                 theState ? theState : @"", kABPersonAddressStateKey,
                 theZip ? theZip : @"", kABPersonAddressZIPKey,
                 theCountry ? theCountry : @"", kABPersonAddressCountryKey,
                 nil];

我使用地址记录中的值来查找地址的坐标(从这个问题和答案中学习了如何做到这一点),然后将其添加到我的地图中:

[mapView addAnnotation: [[[MKPlacemark alloc] initWithCoordinate: theCoordinate
                                               addressDictionary: theAddress] autorelease]];

崩溃肯定似乎是由这个 MKPlacemark 引起的,好像我注释掉 addAnnotation 语句代码不会崩溃一样。

知道发生了什么吗?我猜我在地址记录中没有得到足够的信息,但是错误消息确实没有帮助。

4

2 回答 2

1

您在某处过度释放 NSDictionary 对象。找到它的方法如下:

在项目菜单下,选择“编辑活动可执行文件”。在 Arguments 选项卡中,将一个项目添加到“Variables to be set in the environment:”块中,其中包含 nameNSZombieEnabled和 value YES

快乐的僵尸狩猎。

于 2009-12-18T07:28:40.773 回答
1

theAddress在创建它和将它传递给 MKPlacemark 的 init 方法之间,该 NSDictionary 是否发生了某些事情?我之所以问是因为您似乎正在崩溃,因为您的代码试图将一个CALayer对象视为一个集合类(也就是说,就像它有一个objectForKey:方法),而我在那里看到的唯一集合类是那个地址字典。

于 2009-12-18T07:45:01.027 回答