我想我会分享我对这个问题的解决方案,因为我看到其他人仍在寻找答案。它不是一个很好的解决方案,但它可以解决问题。
- 子类 NSDocumentController 并添加以下内容:
+ (void) setCanOpenUntitledDocument: (BOOL) _canOpenUntitledDocument
{
canOpenUntitledDocument = _canOpenUntitledDocument;
} // End of setCanOpenUntitledDocument:
- (void) openDocument: (id) sender
{
// With iCloud enabled, the app keeps trying to run openDocument: on first launch (before apphasfinishedlaunching gets set.
// This method lets us check and see if the app has finished launching or not. If we try to open a document before
// its finished, then don't let it.
if(!canOpenUntitledDocument)
{
return;
} // End of appHasFinishedLaunching not set
[super openDocument: sender];
} // End of openDocument:
将以下内容添加到您的应用委托中:
- (void) applicationDidFinishLaunching: (NSNotification *) aNotification
{
// Finished launching. Let us open untitled documents.
[SQLProDocumentController setCanOpenUntitledDocument: true];
...
}
和推理 - 通过设置断点,openDocument
我发现它在之前调用或被调用applicationDidFinishLaunching
,这意味着添加这些方法是无用的。同样,这不是很好的代码,但它可以工作并且可以解决问题。(没有其他解决方案对我有用)。applicationShouldOpenUntitledFile
applicationShouldHandleReopen:hasVisibleWindows: