tags:

views:

38

answers:

1

Hello!

I´m newbie. I have three xib files in my cocoa app:

  • "MainMenu.xib" the main window with a toggle button.

  • "CustomView.xib" a custom view.

  • "Alternative.xib" an alternative custom view with different size and number of controls.

My questions are:

  1. How to display a custom view in the main window from "CustomView.xib"?

  2. Toggle "CustomView.xib" and "Alternative.xib" when button is pressed?

  3. Differences if the customs views are in the main xib?

Thanks

A: 

This article is a good place to start. Essentially, you instantiate some owner (that holds the outlets/actions) if it doesn't exist and ask NSBundle to load the nib with that given owner. If all goes well, you'll have your UI all wired up and ready to go.

As for how to toggle between them, this is far too broad to answer. At its most basic, you could always add the custom / alternative views as subviews of individual tab view items in a tabless tab view, asking it to select a given tab when some action is fired. A bit more complicated (only a little bit) would be to use NSView's -replaceSubview:with: to swap them out of some containing superview.

Regarding your third question ... can you please rephrase it? As you phrased it, the differences are a) you'll have more work to do loading it from a separate nib and, b) you won't be able to reuse it (ie, create multiple instances of the same subview assembly), which may or may not be important to you in this case since it seems like you'll only have one instance of the contents of CustomView and Alternative.

Joshua Nozzi
Thanks Joshua! VERY useful answer. It works fine. And your answer for the third question is exactly what I wanted to know. T
Azpiri
Happy to help. Happier if you mark answers 'accepted' if they work for you. :-)
Joshua Nozzi
Already accepted. I´m newbie with this site also ;)
Azpiri