2 ways to make windows, which is right?

Discussion in 'Mac Programming' started by larswik, Aug 16, 2011.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I finished a project a couple weeks ago that had 4 windows all with in the same .xib file that I use the 'makeKeyAndOrderFront'. This worked fine until they click on the red dot to close the window. When they tried to open it again it crashed the program. I ended up removing the red dot in IB.

    The new project I'm working on I made separate .xib files for the different windows. This was a good tutorial on how to do it http://www.youtube.com/watch?v=Z1Erw7aP0EQ by the way. But I am having a heck of a time to get settings I enter into the second window to show up in the first window.

    So I was wondering, is there a rule of thumb when to use a second window in the same xib and MKAOrderFront or create a second .xib file and instantiate a new Window object?
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Most likely the window that crashed was marked as "delete when close". So when the user closed it, the window got removed, you got a garbage pointer, and then you tried to send "makeKeyAndOrderFront" to the garbage pointer.
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    That is what I kind of thought happened. So in my new project as I am still learning I am trying to find out when to create a second window in the same MainMenu.xib, or when to create a new .xib file to a new window?

    Are their any guide lines?
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #4
    I would almost surely use the method described in this video for any sub-window which is more than just trivial. Maybe for something like a simple status window you don't need this method.

    But if there's any separate logic in this second window, it would probably be best to separate out the secondary window's controller from the main window's controller. The point of object-oriented design is to encapsulate logic as much as possible. The method shown in the video meets that goal. Looks very straight-forward to me.
     
  5. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    Thanks for that explanation. I am getting a little lost with second windows and I am more or less approaching it wrong. I was trying to unclutter the 1st window so I created a second window with a button and a test fields. I enter the information and press the NSbutton which should have added the string in the NSTextField to an NSPopUpButton in the first window.

    But it worked fine if I created a second window within the first xib. That is when I wondered when you use one of the other.

    Thanks

    -Lars
     

Share This Page