除了自己的文件类型弹出按钮之外,还将附件视图添加到NSDocument的保存面板(Adding an accessory view to an NSDocument's save panel in addition to its own file type popup button)

我有一个基于NSDocument的应用程序,可以保存到多种文件类型,因此在保存文档时,NSDocument有助于将一个弹出按钮添加到保存面板作为其附件视图,让用户选择他们想要保存为哪种类型。 尼斯。

现在,我有另一个视图,我想要包含在保存面板中,但如果我只是覆盖-[NSDocument prepareSavePanel:]并使用-setAccessoryView:来插入我自己的视图,它将替换文件类型弹出窗口按钮,所以只有我的视图出现在保存面板而不是弹出按钮。

有没有什么方法NSDocument提供我自己的视图它的文件类型弹出窗口? 看起来我可以抓住现有的配件视图,将它与我自己的配件一起打到一个容器视图中,并将其重新放入,但这看起来非常h​​ackish,并且想知道是否有更好的方法来做到这一点,我已经错过。

I have an NSDocument based application that can save to multiple file types, so when saving a document, NSDocument helpfully adds a pop-up button to the save panel as its accessory view that lets the user choose what type they'd like to save as. Nice.

Now, I've got another view that I'd like to include in the save panel, but if I just override -[NSDocument prepareSavePanel:] and use -setAccessoryView: to insert my own view, it replaces the file type pop-up button, so only my view appears in the save panel and not the pop-up button.

Is there any way that NSDocument provides to have both my own view and its file type pop-up appear in the save panel at the same time? It looks like I could grab the existing accessory view, patch it together with my own accessory into a container view, and put that back in, but that seems pretty hackish, and was wondering if there's any better way to do this that I've missed.

最满意答案

不,没有明显更好的方法。 它可能稍微/更好:

在您自己的附件视图笔尖中创建文件类型弹出窗口 在运行时,找到NSSavePanel现有的附件弹出窗口, 在弹出窗口中调用setTarget: / setAction: / setMenu:从现有弹出窗口的设置方式中拉出参数。

这就是我们的应用程序执行操作的方式,并且使用其他控件可以更容易地将文件类型弹出窗口定位,因为它们都在同一个笔尖中。

No, no significantly better way. It may be slightly easier/nicer to:

Create a file type pop-up in your own accessory view nib At run-time, find the NSSavePanel's existing accessory popup, Call setTarget: / setAction: / setMenu: on your popup with arguments pulled from how the existing popup is set.

That's the way our app does things, and it makes it easier to visibly position the file type popup with the rest of your controls, since it's all in the same nib.

更多推荐