Displaying an Alert on Startup

Discussion in 'Mac Programming' started by Spike099, Jul 6, 2007.

  1. macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #1
    Simple question. I have an alert that is displayed using a sheet. When I call the method using init or awakeFromNib it shows the alert in a panel. If I click a button to display it, it works fine. I tried - (void)applicationDidFinishLaunching:(NSNotification *)aNotification which did not do anything at all. The question? What method should I make the call in so it shows in a sheet when the app is started?
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    The sheet shows as a panel when the window you want to attach it to does not yet exist (likely if it's not yet loaded from a nib). In situations when I've wanted to do this I've set a timeout for a short amount of time (say 0.1 - 0.5 seconds) so as the nib gets a chance to load before displaying the sheet.
     
  3. thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #3
    I've thought about doing the same. But, I don't think it's proper. I have shortcut keys that can be pressed in normal operation. What if the user is holding these keys down. This will cause other actions to be preformed before this alert is shown... Otherwise I would have to disable everything and then re-enable everything when the alert is finished.

    There has got to be a way to do this properly using a method like applicationDidFinishLaunching. But one that works. Cause that one didn't do anything at all.
     
  4. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    In my program, I want to display the licence (as a sheet) the first time the user loads a document, I have put the method under:
    -(void)windowDidUpdate:(NSNotification *)aNotification

    For the delegate of the main window for your application. This method is called every time the window updates it's view so will be called as soon as the window appears, once it is no longer white (which looks unprofessional). The windowShown value is stored in the header file, and is set to NO when the delegate is initialized (which should ideally occur before the window is displayed, but it isn't a big deal as this method is called as soon as the user does anything to the window).
    Code:
    -(void)windowDidUpdate:(NSNotification *)aNotification{
    	if(!windowShown){
    		windowShown=YES;
    		//call method to display the sheet here.
    	}
    }
    
     
  5. thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada

Share This Page