Multiple Windows in one XIB File

Discussion in 'Mac Programming' started by BadWolf13, Mar 2, 2010.

  1. BadWolf13 macrumors 6502

    Dec 17, 2009
    I've been wondering something for a while, and I can't seem to figure it out. When I work in Interface Builder, it allows me to have multiple windows within a single IB file, and yet all the example programs that come with Xcode and are available for download from Apple all show separate IB files for each window or panel within a program. Is there a problem with having multiple windows, is it a preference thing, is one method clearly better than the other?
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    No; Yes; and It depends.

    No, there's no problem with multiple windows, if that's how your app is structured.

    Yes, it's mostly preference (or the design sense) of the developer.

    It depends on what the developer is trying to accomplish.

    Ultimately, if you can't think of a good reason for multiple windows in a single nib, then don't worry about it. Just know it's there if you ever want it.
  3. GorillaPaws macrumors 6502a


    Oct 26, 2003
    Richmond, VA
    You've piqued my curiosity. Excluding helper windows, when would it make sense to have multiple windows in a single xib?
  4. Sydde macrumors 68020


    Aug 17, 2009
    Suppose you have a relatively small app that can show a log or status record. Would you use a separate nib/xib for that? Or a small game that has a high-scores window. Putting everything into one nib means everything must be instantiated at launch time, so if the resources are relatively minimal and development is not spread out over a large group, sometimes it is simply easier to put it all into one nib.
  5. BadWolf13 thread starter macrumors 6502

    Dec 17, 2009
    Ok, for example's sake, I'm making a document based program that handles different types of documents, with different windows for each document type, it's likely best to make a different XIB file for each document type?

    If on the other hand, I've got a pop-up window that's too complicated to be created programmatically, would it be a good idea to put it in the same XIB file as the parent window?
  6. HiRez macrumors 603


    Jan 6, 2004
    Western US
    For your example of different document types (meaning, I assume, a "Cocoa Document-Based" app), yes, I would think you would absolutely want to separate those windows into separate XIBs. The controller has to associate a XIB with a document.

    Other than that I would say it's up to you. If it makes sense for things to be together (like accessory panels and views, and so forth), then sure, you could keep them together. Just remember when you load a XIB you load the whole thing, so you might not wish to load things that may not even be used every time your app is run (let's say a preferences panel or export options panel).

Share This Page