Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spike099

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors regular
Original poster
Feb 18, 2007
143
0
Canada
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

macrumors G4
Nov 3, 2005
10,434
12,250
UK
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.
	}
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.