One Modal dialog(window) needed for 2 NIB's

Discussion in 'Mac Programming' started by satyam90, Jan 29, 2008.

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    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.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. thread starter macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    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.

    Code:
    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
    {
         [B][NSApp runModalForWindow:[self window]];[/B]
    }
    .
    .
    .
    .
    .
    .
    .
    - (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?
     

Share This Page