macos – 如何禁用自动重新打开上一个文档?

前端之家收集整理的这篇文章主要介绍了macos – 如何禁用自动重新打开上一个文档?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何禁用自动重新打开上一个文档?

当我执行我的应用程序时,它调用方法readFromData.

但问题是,在我的版本1和版本2之间,我更改了应用程序保存的数据结构.在v1中,根对象是一个数组.在v2中,根对象是一个带有两个键的字典,一个用于字符串,另一个用于数组.

当应用程序加载时,它似乎从数据中加载一个数组,然后尝试从该数组中获取字典键的对象.

我该怎么办 !!??

PS:我试着创建一个NSApplicationDelegate

-(BOOL)applicationShouldOpenUntitledFile:(NSApplication*)app
        {
            return YES; 
        }


        - (BOOL)applicationOpenUntitledFile:(NSApplication *)sender
        {
            return YES ;
        }

但我的应用程序从不调用这些方法.

编辑:

这是调用堆栈:

0   CoreFoundation                      0x00007fff8bc06f56 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff81f37d5e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8bc931be -[NSObject doesNotRecognizeSelector:] + 190
3   CoreFoundation                      0x00007fff8bbf3e23 ___forwarding___ + 371
4   CoreFoundation                      0x00007fff8bbf3c38 _CF_forwarding_prep_0 + 232
5   dictionnaireDouchoutique            0x0000000100007f22 -[Document readFromData:ofType:error:] + 498
6   AppKit                              0x00007fff89af3558 -[NSDocument readFromURL:ofType:error:] + 665
7   AppKit                              0x00007fff8999198c -[NSDocument _initForURL:withContentsOfURL:ofType:error:] + 151
8   AppKit                              0x00007fff89991890 -[NSDocument initForURL:withContentsOfURL:ofType:error:] + 360
9   AppKit                              0x00007fff89991677 -[NSDocumentController makeDocumentForURL:withContentsOfURL:ofType:error:] + 199
10  AppKit                              0x00007fff8999150f __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_5 + 150
11  AppKit                              0x00007fff89991467 __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_4 + 697
12  AppKit                              0x00007fff899911a9 -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] + 530
13  AppKit                              0x00007fff89990d95 __-[NSDocumentController reopenDocumentForURL:withContentsOfURL:display:completionHandler:]_block_invoke_3 + 242
14  libdispatch.dylib                   0x00007fff86329a82 _dispatch_call_block_and_release + 18
15  libdispatch.dylib                   0x00007fff8632b8f2 _dispatch_main_queue_callback_4CF + 308
16  CoreFoundation                      0x00007fff8bb9be7c __CFRunLoopRun + 1724
17  CoreFoundation                      0x00007fff8bb9b486 CFRunLoopRunSpecific + 230
18  HIToolBox                           0x00007fff87d652bf RunCurrentEventLoopInMode + 277
19  HIToolBox                           0x00007fff87d6c56d ReceiveNextEventCommon + 355
20  HIToolBox                           0x00007fff87d6c3fa BlockUntilNextEventMatchingListInMode + 62
21  AppKit                              0x00007fff8973d779 _DPSNextEvent + 659
22  AppKit                              0x00007fff8973d07d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
23  AppKit                              0x00007fff897399b9 -[NSApplication run] + 470
24  AppKit                              0x00007fff899b5eac NSApplicationMain + 867
25  dictionnaireDouchoutique            0x00000001000075d2 main + 34
26  dictionnaireDouchoutique            0x0000000100001984 start + 52

解决方法

使用NSPropertyListSerialization反序列化数据,然后使用respondsToSelector:或isKindOfClass:检查它是什么类型的根对象.如果它是一个数组,处理它;如果是字典,请处理;如果它是您无法识别的任何内容,则返回指示 the file is garbage错误.

猜你在找的cocoa相关文章