我正在尝试向地图添加地标。地标是从完全在通讯簿之外的地址构建的。
我的地标出现在地图上,但是当我尝试捏放大时,我遇到了崩溃:
*** -[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 语句代码不会崩溃一样。
知道发生了什么吗?我猜我在地址记录中没有得到足够的信息,但是错误消息确实没有帮助。