我正试着在地图上添加一个地标。地标是从一个完全不在地址簿的地址中创建的。
我的地标出现在地图上,但当我试图抓取放大时,我遇到了崩溃:
*** -[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];我使用地址记录中的值来查找地址的坐标(从this question & answer学习了如何执行此操作),然后将其添加到我的地图中:
[mapView addAnnotation: [[[MKPlacemark alloc] initWithCoordinate: theCoordinate
addressDictionary: theAddress] autorelease]];崩溃显然是由这个MKPlacemark引起的,就好像我注释掉了addAnnotation语句代码没有崩溃一样。
知道是怎么回事吗?我猜我在地址记录中没有得到足够的信息,但是错误消息真的没有帮助。
发布于 2009-12-18 15:28:41
您在某处过度释放了NSDictionary对象。下面是你如何找到它的:
在项目菜单下,选择“编辑活动的可执行文件”。在Arguments选项卡中,向"Variables to be set in the environment:“块中添加一项,名称为NSZombieEnabled,值为YES。
僵尸猎人快乐。
发布于 2009-12-18 15:45:01
在您创建theAddress NSDictionary和将其传递给MKPlacemark的init方法之间,是否发生了什么?我之所以问这个问题,是因为您的代码试图将CALayer对象视为集合类(即它具有objectForKey:方法),而我在其中看到的惟一集合类就是address字典。
https://stackoverflow.com/questions/1923525
复制相似问题