2

我有一个 NSDocument 的子类,每当我使用 [self close] 来避免新文档的默认“保存”对话框时,它就会崩溃:

2013-02-25 15:23:06.338 MyApp[692:403] An uncaught exception was raised
2013-02-25 15:23:06.338 MyApp[692:403] NSWindow: -_newFirstResponderAfterResigining is not a valid message outside of a responder's implementation of -resignFirstResponder.
2013-02-25 15:23:06.356 MyApp[692:403] (
0   CoreFoundation                      0x00007fff8b2cdf56 __exceptionPreprocess + 198
1   libobjc.A.dylib                     0x00007fff88c00d5e objc_exception_throw + 43
2   CoreFoundation                      0x00007fff8b2cdd8a +[NSException raise:format:arguments:] + 106
3   CoreFoundation                      0x00007fff8b2cdd14 +[NSException raise:format:] + 116
4   AppKit                              0x00007fff858e0c34 -[NSWindow _newFirstResponderAfterResigning] + 164
5   AppKit                              0x00007fff85882c8a -[NSTextView(NSSharing) resignFirstResponder] + 54
6   AppKit                              0x00007fff8536dd79 -[NSWindow makeFirstResponder:] + 429
7   AppKit                              0x00007fff85488dfb -[NSWindow dealloc] + 802
8   AppKit                              0x00007fff8528b955 -[NSWindow release] + 535
9   AppKit                              0x00007fff858b541c __destroy_helper_block_4 + 26
10  libsystem_blocks.dylib              0x00007fff8702b174 _Block_release + 181
11  libdispatch.dylib                   0x00007fff84ab28f2 _dispatch_main_queue_callback_4CF + 308
12  CoreFoundation                      0x00007fff8b262e7c __CFRunLoopRun + 1724
13  CoreFoundation                      0x00007fff8b262486 CFRunLoopRunSpecific + 230
14  HIToolbox                           0x00007fff8d64e2bf RunCurrentEventLoopInMode + 277
15  HIToolbox                           0x00007fff8d65556d ReceiveNextEventCommon + 355
16  HIToolbox                           0x00007fff8d6553fa BlockUntilNextEventMatchingListInMode + 62
17  AppKit                              0x00007fff85252779 _DPSNextEvent + 659
18  AppKit                              0x00007fff8525207d -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
19  AppKit                              0x00007fff8524e9b9 -[NSApplication run] + 470
20  AppKit                              0x00007fff854caeac NSApplicationMain + 867
21  MyApp                                0x00000001059098d2 main + 34
22  MyApp                                0x00000001059098a4 start + 52
23  ???                                 0x0000000000000003 0x0 + 3
)

有没有人以前见过这个,或者任何人都可以建议一种更好/正确的方法来关闭 NSDocument 而不显示保存对话框?

4

1 回答 1

3

因此,从您的后续评论来看,您正在尝试做的是在特定情况下取消标准关闭确认表。一些方法可以做到这一点:

  • 采用原地自动保存,摆脱了手动保存文档的古老范式
  • 覆盖-[NSDocument canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:],因此它告诉代表“是的,您可以关闭”,而不是呈现工作表
  • 发布帖子后,致电[document updateChangeCount: NSChangeCleared]通知文档您认为已保存
于 2013-04-11T19:16:16.563 回答