简体   繁体   中英

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 -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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM