PDA

View Full Version : One Modal dialog(window) needed for 2 NIB's




satyam90
Jan 29, 2008, 07:35 AM
I have 2 NIB's "A" & "B". At different instances I need to show a Modal dialog(window or panel) from both the NIB's.
Currently I created one more NIB "C" with NSWindow object and showing from both NIB's using showWindow method. But when "C" is shown from "A" or "B", "C" is shown and normal processing is taking place in "A" & "B" and closing when it reaches that command. But I cant to stop "A" & "B" processing untill "C" is closed.
Is there any method or widget available to make my window modal.



robbieduncan
Jan 29, 2008, 08:05 AM
Have you read the documentation (http://developer.apple.com/documentation/Cocoa/Conceptual/WinPanel/Concepts/UsingModalWindows.html)? It's all there...

satyam90
Jan 30, 2008, 03:00 AM
I have gone through the documentation that u specified.
I am showing the window first and then calling "runModalForWindow" with my window as parameter. Everytime, I have to do this to make it modal window.
I tried to put "runModalForWindow" at the end of windowDidLoad, and stopModal before closing the window. Here I observed that the window is shown, when I press cancel, it is closing and again it is showing, when I press cancel, it is closed.


static id instance = nil;
+(id) sharedInstance
{
if(instance == nil)
{
instance = [[[self class]alloc]init];
}
return instance;
}

- (id) init
{
if (self = [super initWithWindowNibName:@"MyWindName" owner:self])
{
}
return self;
}

-(void)windowDidLoad
{
[NSApp runModalForWindow:[self window]];
}
.
.
.
.
.
.
.
- (IBAction) onCancel:(id)sender
{
[NSApp stopModal];
[[self window] close];
}



Can anyone tell me why it is getting called twice? Also I observed that "init" is also getting called twice. One instance is I am calling "init" is in createing the instance. When second time "init" is getting called?