PDA

View Full Version : Multiple Nib Instance




ruhi
Aug 6, 2009, 08:01 AM
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.



kainjow
Aug 6, 2009, 01:50 PM
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:
// .h
MyWindowController *winController;

// .m
if (!winController)
winController = [[MyWindowController alloc] init];
[winController showWindow:nil];

robbieduncan
Aug 7, 2009, 04:31 AM
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:
// .h
MyWindowController *winController;

// .m
if (!winController)
winController = [[MyWindowController alloc] init];
[winController showWindow:nil];

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).

ruhi
Aug 7, 2009, 06:36 AM
Thanks a lot.

It working fine now.

Thanks,
ruhi