我的应用程序中,我正在尝试将MKPolylines
数组存储到NSUserDefaults
中。
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:overlays];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"];
提供:
[MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x169c20`
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-
[MKPolyline encodeWithCoder:]: unrecognized
selector sent to instance 0x1c57e0'
编辑:我取得了一些进展。MKPolylineView
符合NSCoding
协议,因此我已将我的MKPolyline
数组转换为MKPolylineView
数组。问题在于,当我想要稍后将它们添加回地图时,我无法将它们转换回MKPolyline
。有什么办法吗?
代码崩溃在这里:
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:@"theKey"];
NSArray* overlays = [NSKeyedUnarchiver unarchiveObjectWithData:data];
for(MKPolylineView* a in overlays)
[mapView addOverlay:a.overlay];
2011-10-17 21:15:56.416 Trail Tracker[4269:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x34b2f8bf 0x36c3a1e5 0x34a8420f 0x35697595 0x6257 0x62db 0x365f77ff 0x36601d53 0x36601cc1 0x366a1339 0x366a014f 0x366fad97 0x649b 0x36671565 0x366e9ce7 0x31fcc943 0x34b03a63 0x34b036c9 0x34b0229f 0x34a854dd 0x34a853a5 0x351f9fed 0x365ec743 0x2c75 0x2c34)
terminate called throwing an exception(gdb)