[英]When Application quits, NSDocument's isDocumentEdited method always returns false
In a document-based application, any change in a document is signalled by a在基于文档的应用程序中,文档中的任何更改都由
[self updateChangeCount: NSChangeDone];
At any time, when debugging, the [document isEdited]
returns TRUE, as far as the document has been edited.在任何时候,调试时,只要文档已被编辑,
[document isEdited]
返回 TRUE。 The doc's window displays "Modified" besides the document's name.除了文档名称之外,文档的窗口还显示“已修改”。 When I quit application, my app delegate reviews all opened documents, and check whether they've been edited or not, using this loop:
当我退出应用程序时,我的应用程序委托检查所有打开的文档,并使用以下循环检查它们是否已被编辑:
NSUInteger needsSaving = 0;
while (count--) {
NSWindow *window = [windows objectAtIndex:count];
Document *document = [Document documentForWindow:window];
if (document && [document isDocumentEdited]) needsSaving++;
}
It appears that for any document —modified or not— the [document isDocumentEdited];
似乎对于任何文件——无论是否修改——
[document isDocumentEdited];
always returns FALSE!总是返回 FALSE! So that the review change/save process cannot be called.
因此无法调用审核更改/保存过程。 If I check the
[window isDocumentEdited]
, it also returns FALSE despite the fact that "Modified" is written in the title bar of the window.如果我检查
[window isDocumentEdited]
,它也会返回 FALSE,尽管“Modified”写在窗口的标题栏中。
When the applications quits, the changes are eventually saved (automatically) but without informing the user.当应用程序退出时,更改最终会(自动)保存,但不会通知用户。 This is a very disturbing behaviour!
这是一种非常令人不安的行为!
Any idea of what could explain that the isDocumentEdited
boolean is reset to FALSE somewhere before entering this process?知道什么可以解释
isDocumentEdited
布尔值在进入此过程之前在某处重置为 FALSE 吗?
I checked all the code to see if there wasn't any [self updateChangeCount: NSChangeCleared]
that could be run somewhere, but it's not the case.我检查了所有代码,看看是否有任何
[self updateChangeCount: NSChangeCleared]
可以在某处运行,但事实并非如此。 I can circumvent the problem using a custom updateChange counting system in my Document subclass, but I would rather use the built-in process.我可以在我的 Document 子类中使用自定义 updateChange 计数系统来规避这个问题,但我更愿意使用内置过程。
Using Xcode 10 under Mojave, with a 10.12 target在 Mojave 下使用 Xcode 10,目标为 10.12
isDocumentEdited is documented as a "value that indicates whether the document has unsaved changes". isDocumentEdited 被记录为“指示文档是否有未保存更改的值”。 The behaviour might be happening if autosavesInPlace is enabled.
如果启用了 autosavesInPlace,则可能会发生该行为。 There won't be unsaved changes at application quit.
退出应用程序时不会有未保存的更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.