PDA

View Full Version : Displaying an Alert on Startup




Spike099
Jul 6, 2007, 06:20 PM
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?



robbieduncan
Jul 7, 2007, 03:37 AM
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.

Spike099
Jul 7, 2007, 10:14 AM
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.

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.

Eraserhead
Jul 7, 2007, 11:43 AM
In my program (http://www.erasersoft.com/main2/Download.html), 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).

-(void)windowDidUpdate:(NSNotification *)aNotification{
if(!windowShown){
windowShown=YES;
//call method to display the sheet here.
}
}

Spike099
Jul 7, 2007, 12:20 PM
Thanks Eraserhead, works like a charm.