首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MKPlacemark放大MKMapView时崩溃

使用MKPlacemark放大MKMapView时崩溃
EN

Stack Overflow用户
提问于 2009-12-18 02:01:48
回答 2查看 2.2K关注 0票数 0

我正试着在地图上添加一个地标。地标是从一个完全不在地址簿的地址中创建的。

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

代码语言:javascript
复制
*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0'

下面是我如何设置地址的:

代码语言:javascript
复制
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学习了如何执行此操作),然后将其添加到我的地图中:

代码语言:javascript
复制
[mapView addAnnotation: [[[MKPlacemark alloc] initWithCoordinate: theCoordinate
                                               addressDictionary: theAddress] autorelease]];

崩溃显然是由这个MKPlacemark引起的,就好像我注释掉了addAnnotation语句代码没有崩溃一样。

知道是怎么回事吗?我猜我在地址记录中没有得到足够的信息,但是错误消息真的没有帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-12-18 15:28:41

您在某处过度释放了NSDictionary对象。下面是你如何找到它的:

在项目菜单下,选择“编辑活动的可执行文件”。在Arguments选项卡中,向"Variables to be set in the environment:“块中添加一项,名称为NSZombieEnabled,值为YES

僵尸猎人快乐。

票数 1
EN

Stack Overflow用户

发布于 2009-12-18 15:45:01

在您创建theAddress NSDictionary和将其传递给MKPlacemark的init方法之间,是否发生了什么?我之所以问这个问题,是因为您的代码试图将CALayer对象视为集合类(即它具有objectForKey:方法),而我在其中看到的惟一集合类就是address字典。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1923525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档