开发者

Adding an accessory view to an NSDocument's save panel in addition to its own file type popup button

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 -s开发者_开发技巧etAccessoryView: 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.


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

  1. Create a file type pop-up in your own accessory view nib
  2. At run-time, find the NSSavePanel's existing accessory popup,
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜