3 usability cocoa objective-c nsdocument
我正在创建一个NSDocument应用程序,它有两种文档类型:Website和Web Service.这是在我的Info.plist中:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Website</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>website</string>
</array>
<key>LSTypeIsPackage</key>
<true/>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>NSDocumentClass</key>
<string>AWWebSite</string>
</dict>
<dict>
<key>CFBundleTypeName</key>
<string>Web Service</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>webservice</string>
</array>
<key>LSTypeIsPackage</key>
<true/>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>NSDocumentClass</key>
<string>AWWebService</string>
</dict>
</array>
Run Code Online (Sandbox Code Playgroud)
现在,每当用户打开应用程序时,从菜单栏中选择"新建"项目,或者在没有打开窗口时单击Dock图标,我想显示一个包含两个选项的窗口,每个选项用于一种文档类型.谁能帮我这个?谢谢
你需要做的是覆盖- [NSDocumentController newDocument:].NSDocumentController是响应者链的一部分,是最终处理newDocument:它发送的消息的对象.
从那里,你可以告诉你喜欢的任何对话,然后调用makeUntitledDocumentOfType:error:,addDocument:,makeWindowControllers和showWindows.这是做什么的openUntitledDocumentAndDisplay:error:.
但问题是,这NSDocumentController是一个单例,所以你需要确保它是你的实例化的子类,而不是Apple的.通常,您可以通过将子类的对象添加到MainMenu.xib或首先加载任何NIB来执行此操作.这通常足以确保您的子类首先被创建并成为单例.
| 归档时间: |
|
| 查看次数: |
681 次 |
| 最近记录: |