How can I create a document-based application that cannot create a new document?

China☆狼群 提交于 2020-01-13 19:11:50

问题


I have a document-based application that is designed to process existing documents, not to create new documents.

How do I prevent the application from creating a new, blank document when launched by opening it from the Finder?


回答1:


There is an NSApplication delegate protocol method you can implement.

 - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
    return NO;
}

Here's the documentation




回答2:


Depending on what you are specifically doing, you might want to override newDocument: or applicationOpenUntitledFile: or otherwise stop the user from invoking it via the File->New menu.

However, the answer above, using the delegate method applicationShouldOpenUntitledFile: will handle the common situations where you'd need that behavior.



来源:https://stackoverflow.com/questions/1734229/how-can-i-create-a-document-based-application-that-cannot-create-a-new-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!