Crash in Snow Leopard - Alert

Discussion in 'Mac Programming' started by amit-battan, Sep 21, 2009.

  1. amit-battan macrumors newbie

    Joined:
    Sep 10, 2009
    #1
    Hello Everyone

    I am using following code for the Alert this code works fine in Leopard But in snow Leopard application crashes after showing alert


    Code:
    alert = [[[NSAlert alloc] init] autorelease];
    [alert addButtonWithTitle:@"OK"];
    [alert setMessageText:@"Updated Successfully!"];
    [alert setAlertStyle:NSWarningAlertStyle];
    [alert beginSheetModalForWindow:mainWindow modalDelegate:self didEndSelector:@selector(alertDidEnd4:returnCode4:contextInfo4:) contextInfo:nil];
     
    - (void)alertDidEnd4:(NSAlert *)alert returnCode4:(int)returnCode contextInfo4:(void *)contextInfo{
    }
    
    I have also tried to use sheet here, but same thing happens If I comment the alert code then application works fine

    Please suggest me if anything wrong in my code, or any alternative way

    Thanks
    Amit Battan
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Don't autorelease the alert. It should exist until after the sheet is dismissed. Put the autorelease in your alertDidEnd4 method.
     

Share This Page