如何禁用自动重新打开上一个文档?(How to disable the auto

编程入门 行业动态 更新时间:2024-10-10 03:24:05
如何禁用自动重新打开上一个文档?(How to disable the auto-reopening of the last document?)

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


当我执行我的应用程序时,它调用方法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

How to disable the auto-reopening of the last document ?


When I execute my application, it calls the method readFromData.

But, the problem is that between my version 1 and my version 2, I changed the structure of the data that is saved by the application. In v1, the root object was an array. In v2, the root object is a dictionnary with two keys, one for a string, and one for an array.

When the application loads, it seems that it load from the data an array and then tries to get from this array an object for the keys of the dictionnary.

What shall I do !!??

PS : I tried to create a NSApplicationDelegate with

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

but these methods are never called by my application.


EDIT :

Here is the call stack :

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:检查它是什么类型的根对象。 如果它是一个数组,处理它; 如果是字典,请处理; 如果它是您无法识别的任何内容,则返回错误,指示该文件是垃圾 。

Use NSPropertyListSerialization to deserialize the data, then use respondsToSelector: or isKindOfClass: checks to see what kind of root object it handed you. If it's an array, handle that; if it's a dictionary, handle that; if it's anything you don't recognize, return an error indicating that the file is garbage.

更多推荐

本文发布于:2023-08-04 01:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1402391.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   disable   auto

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!