cocoa + modal dialogue box not getting closed

Discussion in 'Mac Programming' started by goyalpk, Aug 27, 2009.

  1. goyalpk macrumors newbie

    Aug 7, 2009
    Hi Guys I am trying to display a custom modal dialogue box and am doing it the following way:

    EncPasswordSheet is of IBOutlet NSWindow * type.

    @implementation EncryptionPasswordSheet

    -(id)init { return self; }

    (void)showCustomDlg: (NSWindow *)window { if (!EncPasswordSheet) {

    [NSBundle loadNibNamed: @"EncryptionPasswordDlg" owner: self];

    [NSApp beginSheet:EncPasswordSheet modalForWindow:window modalDelegate:nil didEndSelector:nil contextInfo:nil]; [NSApp runModalForWindow: EncPasswordSheet];

    [NSApp endSheet: EncPasswordSheet]; [EncPasswordSheet orderOut: self];


    (IBAction)getPasswordFromSheet: (id)sender {

    password = [passwordField stringValue];
    [NSApp stopModal]; }

    (IBAction)cancelEncPasswordSheet: (id)sender {

    password = nil; [NSApp stopModal];



    The problem is that the dialogue box is getting displayed well and its taking input and on pressing ok or cancel, their respt IBAction methods are getting executed and program is continuing to execute except with one problem: the dialogue box is not getting out of the way i.e its not getting clsed or dissappearing. Please tell where i am going wrong.

  2. kainjow Moderator emeritus


    Jun 15, 2000
    Don't use beginSheet and runModal together. They should be used separately. If you don't understand this go read up on modal windows and sheets at
  3. goyalpk thread starter macrumors newbie

    Aug 7, 2009

Share This Page