Objective c 获取错误:从NSUserDefaults对象检索数据时,将无法识别的选择器发送到实例0x7fe2b1e71b90

Objective c 获取错误:从NSUserDefaults对象检索数据时,将无法识别的选择器发送到实例0x7fe2b1e71b90,objective-c,nsmutablearray,nsuserdefaults,nsdata,Objective C,Nsmutablearray,Nsuserdefaults,Nsdata,获取错误:从NSUserDefaults对象检索数据时,将无法识别的选择器发送到实例0x7fe2b1e71b90 Mycode是: NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableArray *archiveArray = [[NSMutableArray alloc] init]; [_StarredImageUrl addObject:[_photoURLsLargeImage objec

获取错误:从NSUserDefaults对象检索数据时,将无法识别的选择器发送到实例0x7fe2b1e71b90

Mycode是:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *archiveArray = [[NSMutableArray alloc] init];
[_StarredImageUrl addObject:[_photoURLsLargeImage  objectAtIndex:gesture.view.tag]];

NSData *personEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:_StarredImageUrl];
[archiveArray addObject:personEncodedObject];
[defaults setObject:archiveArray forKey:@"items"];
[defaults synchronize];
NSLog(@"Starred URL : %@",_StarredImageUrl);

NSLog(@"Starred URL : %@",personEncodedObject);
NSUserDefaults *defaults1 = [NSUserDefaults standardUserDefaults];
NSData *encodedObject = [defaults1 objectForKey:@"items"];
NSLog(@"%@",encodedObject);
_SavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];
我正在尝试将photoUrl的数组保存在NSUserDefaults中,并从相同的NSUserDefaults加载数据,以验证是否正确保存了数据

但我在最后一行代码中遇到错误,在各种门户网站上搜索过,无法解决,请有人帮忙

完全错误:

2016-04-10 01:07:39.797 FlickrP[4450:156655] -[__NSCFArray bytes]: unrecognized selector sent to instance 0x7fe2b1e71b90 2016-04-10 01:07:39.848 FlickrP[4450:156655] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray bytes]: unrecognized selector sent to instance 0x7fe2b1e71b90' *** First throw call stack: ( 0 CoreFoundation 0x000000010fcb6e65 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010f3a6deb objc_exception_throw + 48 2 CoreFoundation 0x000000010fcbf48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010fc0c90a ___forwarding___ + 970 4 CoreFoundation 0x000000010fc0c4b8 _CF_forwarding_prep_0 + 120 5 CoreFoundation 0x000000010fc21dc0 CFStringCreateFromExternalRepresentation + 32 6 Foundation 0x000000010ef953c6 -[NSPlaceholderString initWithData:encoding:] + 115 7 FlickrP 0x000000010ee9eb7b -[ResultstTable Imagetapped:] + 731 8 UIKit 0x000000011054be73 _UIGestureRecognizerSendTargetActions + 153 9 UIKit 0x00000001105484e5 _UIGestureRecognizerSendActions + 162 10 UIKit 0x00000001105464e2 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843 11 UIKit 0x000000011054e9a0 ___UIGestureRecognizerUpdate_block_invoke904 + 79 12 UIKit 0x000000011054e83e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342 13 UIKit 0x000000011053c101 _UIGestureRecognizerUpdate + 2634 14 UIKit 0x00000001100d3f8a -[UIWindow _sendGesturesForEvent:] + 1137 15 UIKit 0x00000001100d51c0 -[UIWindow sendEvent:] + 849 16 UIKit 0x0000000110083b66 -[UIApplication sendEvent:] + 263 17 UIKit 0x000000011005dd97 _UIApplicationHandleEventQueue + 6844 18 CoreFoundation 0x000000010fbe2a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 19 CoreFoundation 0x000000010fbd895c __CFRunLoopDoSources0 + 556 20 CoreFoundation 0x000000010fbd7e13 __CFRunLoopRun + 867 21 CoreFoundation 0x000000010fbd7828 CFRunLoopRunSpecific + 488 22 GraphicsServices 0x0000000113491ad2 GSEventRunModal + 161 23 UIKit 0x0000000110063610 UIApplicationMain + 171 24 FlickrP 0x000000010ee9cebf main + 111 25 libdyld.dylib 0x00000001123f292d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) 2016-04-10 01:07:39.797 FlickrP[4450:156655]-[\uu nsfarray bytes]:发送到实例0x7fe2b1e71b90的无法识别的选择器 2016-04-10 01:07:39.848 FlickrP[4450:156655]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[\u NSCFArray bytes]:未识别的选择器发送到实例0x7fe2b1e71b90” ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x000000010fcb6e65例外预处理+165 1 libobjc.A.dylib 0x000000010f3a6deb objc_异常_抛出+48 2 CoreFoundation 0x000000010fcbf48d-[NSObject(NSObject)不识别选择器:][205 3 CoreFoundation 0x000000010fc0c90a\uuuuuuuuuuuuuuuuuuuuuuuuu+970 4 CoreFoundation 0x000000010fc0c4b8\u CF\u转发\u准备\u 0+120 5 CoreFoundation 0x000000010fc21dc0 CFStringCreateFromExternalRepresentation+32 6基金会0x000 000 010EF953C6- [ NStPosiHeldStudio字符串In与数据:编码:] + 115 7 FlickrP 0x000000010ee9eb7b-[ResultsAttable Imagetapped::][731 8 UIKit 0x000000011054be73 _UIgestureRecognitizerSendTargetActions+153 9 UIKit 0x00000001105484e5 _UIgestureRecognitizerSendActions+162 10 UIKit 0x00000001105464e2-[UIgestureRecognitor\u updategestruewevent:buttonEvent:+843 11 UIKit 0x000000011054e9a0 \uuuuuuuuuuuuuuuuuuuuigestureRecogenerUpdate\uuuBlock\uuInvoke904+79 12 UIKit 0x000000011054e83e _UIgestureIdentifizerRemoveObjectsFromarrayandApplyBlock+342 13 UIKit 0x000000011053c101\u UIgestureIdentifizerUpdate+2634 14 UIKit 0x00000001100d3f8a-[UIWindow\u sendGesturesForEvent:+1137 15 UIKit 0x00000001100d51c0-[UIWindow sendEvent:][849 16 UIKit 0x0000000110083b66-[UIApplication sendEvent:+263 17 UIKit 0x000000011005dd97 _UIApplicationHandleEventQueue+6844 18 CoreFoundation 0x000000010fbe2a31\uuuu CFRUNLOOP\u正在调用\u OUT\u以执行\u函数\uuuu+17 19 CoreFoundation 0x000000010fbd895c__CFRunLoopDoSources0+556 20 CoreFoundation 0x000000010fbd7e13__CFRunLoopRun+867 21 CoreFoundation 0x000000010fbd7828 CFRunLoopRunSpecific+488 22图形服务0x0000000113491ad2 GSEventRunModal+161 23 UIKit 0x000000011006610 UIApplicationMain+171 24 FlickrP 0x000000010ee9cebf干管+111 25 libdyld.dylib 0x00000001123f292d开始+1 ) libc++abi.dylib:以NSException类型的未捕获异常终止 (lldb)
你遗漏了错误的重要部分。显示问题中的完整错误,并指出导致错误的具体行。您好,我已经添加了完整错误,我在最后一行代码中得到了此错误:_SavedArray=[NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];您正在将
NSArray
而不是
NSData
传递给
unarchiveObjectWithData:
方法。