copy a window? (cocoa)

Discussion in 'Mac Programming' started by dale.albiston, May 10, 2008.

  1. dale.albiston macrumors member

    Joined:
    Sep 29, 2006
    #1
    assume I have a window in a nib file, the nib file is loaded and the controller has a pointer to it.

    I can show this window via:

    [myWindow makeKeyAndOrderFront];

    this works fine

    Q: assume I want a copy of this window, say for example its a property window I may want several of for different data objects. I still wish to define this window in the nib file. how do I create a new window that is a copy of the current one?. I'm assuming there will be a way to create a new object pointer, but how can I tell it to initialise to a copy of another object?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The window will be owned by a NSWindowController subclass. Create another instance of that and it'll create a copy of window from the nib ready to use.

    Having said that it sounds like you are writing a document based app. So choose that template and this will all be handled for you :)
     
  3. dale.albiston thread starter macrumors member

    Joined:
    Sep 29, 2006
    #3
    mmm lets see so if i create a new instance of the controller it will create a new copy of the window i can use?

    fair enough i'll have to try.

    I have looked at the document approach, not sure how to have several different types of 'document', with different window types though.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Rereading it you probably don't want to use the document architecture for this.
     
  5. dale.albiston thread starter macrumors member

    Joined:
    Sep 29, 2006
    #5
    i think i'm getting there, albeit slowly.

    been recommended to try and load an instance of the nib file each time i need a window and run that way..

    I'm tending towards each window getting a seperate controller object, where the controllers are basically just targets for the clicks and whatnots a window generates, and have any logic required to manipulate the window, a seperate data controller driving it if required (hence two windows talk to one data object)

    I think this is how its all meant to work..

    pity really, this is one thing thats a non issue with vb.net. i.e. a form is an object and something along the lines of

    myWindow *x = [[myWindow alloc] init];

    would be all thats required. there may still be a way of doing this with a function to create windows and return an object reference for it.

    ohh the joys of porting vb.net to something faster and usable ont he mac
     
  6. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #6
    Sounds like what you should do.
    The problem then is that what do you link the IBOutlet's in the window controller to, and how to do you know which window you are connected to? In Cocoa each Window needs a separate window controller instance for each version.

    Personally I see your point about VB.NET but I think its the difference between how the API's work and in terms of goodness its really a wash.
     

Share This Page