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

faffoo

macrumors 6502
Original poster
May 22, 2008
293
46
Glasgow, UK
Hi there,

I have an app delegate, and a NSWindowController that I am initialising and allocating with a set up XIB. My question:

I would like to show an NSAlert as a sheet on this new window, as soon as the window is shown. How can i accomplish this?

Regards
Matt
 
Override windowDidLoad in your NSWindowController and show the alert sheet from there.

Hi there,

When i do that, it shows, but not in a sheet layout. Also, any interface elements I add to the alert that I have set up in a XIB will not be added because at that point for some reason they are still nil.

Any reason why I am not getting the slick animation and the alert showing as a sheet?

All help appreciated
Matt
 
Hi there,

When i do that, it shows, but not in a sheet layout. Also, any interface elements I add to the alert that I have set up in a XIB will not be added because at that point for some reason they are still nil.

Any reason why I am not getting the slick animation and the alert showing as a sheet?

All help appreciated
Matt

I can only guess. In my SimpleBrowser app, I show an alert if there's no internet connectivity using this technique. Although, it's literally an NSAlert, not a custom sheet. Can you post the relevant code? Particularly when and how you load the sheet.
 
I can only guess. In my SimpleBrowser app, I show an alert if there's no internet connectivity using this technique. Although, it's literally an NSAlert, not a custom sheet. Can you post the relevant code? Particularly when and how you load the sheet.

Code:
NSProgressIndicator *progressIndic = [[NSProgressIndicator alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 400, 20))];
    [progressIndic setStyle:NSProgressIndicatorBarStyle];
    [progressIndic startAnimation:nil];
    downloading = [NSAlert alertWithMessageText:@"Getting details" defaultButton:@"Use" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", @"We are now attempting to contact our servers, and get your current licensing information. Please wait a moment or two."];
    [downloading setAccessoryView:progressIndic];
    NSButton *button = [[downloading buttons] objectAtIndex:0];
    [button setHidden:YES];
    [downloading beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
    [progressIndic release];

shows the alert view but as a modal, not as the desired sheet i would like.

I removed references to anything in XIB files here as they were all returning nil at this point. But i still need to be able to access controls in the xib file, any ideas when i can do this?

Any ideas?
Regards
Matt
 
Last edited:
You could try showing the alert in the showWindow: method (assuming it's being used):

Code:
- (IBAction)showWindow:(id)sender {
    [super showWindow:sender];

    // show your NSAlert here
}

Or use windowDidBecomeKey: and show it there, if it's not already visible.
 
You could try showing the alert in the showWindow: method (assuming it's being used):

Code:
- (IBAction)showWindow:(id)sender {
    [super showWindow:sender];

    // show your NSAlert here
}

Or use windowDidBecomeKey: and show it there, if it's not already visible.

I found the problem, which may come in helpful for others searching:

In my XIB file i had added a general object and set its class to my controller and connected my controls to the outlets through that control.

I changed that so that the files owner had its class set to my controller and linked things up through that. Now, no problems.

Thanks for your help everyone!

Regards
Matt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.