Multiple Nib Instance

Discussion in 'Mac Programming' started by ruhi, Aug 6, 2009.

  1. ruhi macrumors member

    Joined:
    Jun 17, 2009
    #1
    Hello,

    i have a button on my MainMenu.xib window. Clicking over it causes another nib(mainWindow.xib) to load which has some text written on it.

    Is there any way through which i can check whether or not any previous instance of nib is already loaded so that clicking over the button again will not load mainWindow.xib until first instance of mainWindow.xib is unloaded.

    Thanks,
    Ruhi.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Wrap your nib code into an NSWindowController (which handles loading the nib). Then you can store a reference to that controller and only load it once. For example:
    Code:
    // .h
    MyWindowController *winController;
    
    // .m
    if (!winController)
        winController = [[MyWindowController alloc] init];
    [winController showWindow:nil];
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    You could even make the window controller a singleton object to ensure you only ever load it once, even if you try and create another window controller instance (say if the window is an inspector that there can only ever be one of).
     
  4. ruhi thread starter macrumors member

    Joined:
    Jun 17, 2009
    #4
    Multiple Nib Instance

    Thanks a lot.

    It working fine now.

    Thanks,
    ruhi
     

Share This Page