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

gwelmarten

macrumors 6502
Original poster
Jan 17, 2011
476
0
England!
Hi
Sorry - this is relatively basic, but I can't get it. I'm trying to display an NSAlert in my document based Mac Application. Unfortunately, I keep getting the error:
Code:
Use of undeclared identifier 'window'; did you mean '_windows'?
My code for displaying the NSAlert is:

Code:
- (void)showNewUserMessage {
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setAlertStyle:NSInformationalAlertStyle];
    [alert setMessageText:@"IMPORTANT INFORMATION"];
    [alert setInformativeText:@"TEXT"];   

    [alert beginSheetModalForWindow:window modalDelegate:self];
}

and in the related header file, I have:
Code:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
- (void)showNewUserMessage;

Does anybody know what is causing this? As I understand it, beginSheetModalForWindow:window, 'window' should be the name of the view that the alert should appear in. How would I find that? I have read that I should import foundation/foundation.h in my header, but this didn't make a difference.

Thanks in advanced,
Sam
 
What class is this code in? If it's a subclass of NSView, then you can probably do something like:

Code:
[alert beginSheetModalForWindow:[self window] modalDelegate:self];
 
Thanks for that - now I know how to tell it which sheet to display in. However, I am still getting a different error, which I now presume is due to a framework problem.
I've now got:
Code:
- (void)showNewUserMessage {
    NSAlert *alert = [[NSAlert alloc] init];
    [alert setAlertStyle:NSInformationalAlertStyle];
    [alert setMessageText:@"IMPORTANT INFORMATION"];
    [alert setInformativeText:@"TEXT"];
    [alert beginSheetModalForWindow:[self windowForSheet]
                      modalDelegate:self];

}

Which I call in:

Code:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController {
[self showNewUserMessage];
}

My header file has these imports in addition to what I posted previously:

Code:
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <AppKit/AppKit.h>

I believe foundation is needed for NSAlert.
The Problem
So basically, when I run it the application appears in the dock but the window does not open. The following is printed in the console:

Code:
2012-05-04 17:54:20.609 Anonymous Browser Pro[937:707] -[NSAlert beginSheetModalForWindow:modalDelegate:]: unrecognized selector sent to instance 0x103113290
2012-05-04 17:54:20.610 Anonymous Browser Pro[937:707] -[NSAlert beginSheetModalForWindow:modalDelegate:]: unrecognized selector sent to instance 0x103113290
2012-05-04 17:54:20.612 Anonymous Browser Pro[937:707] -[NSAlert beginSheetModalForWindow:modalDelegate:]: unrecognized selector sent to instance 0x10030ef50
2012-05-04 17:54:20.613 Anonymous Browser Pro[937:707] -[NSAlert beginSheetModalForWindow:modalDelegate:]: unrecognized selector sent to instance 0x10030ef50

And I get this yellow error in Xcode:

Code:
Instance method '-beginSheetModalForWindow:modalDelegate:' not found (return type defaults to 'id')

(see attached screenshot)

Any ideas? I've tried fiddeling with the imports and googling the instance method, but I'm not sure.

Thanks for any help in advance,
Sam
 

Attachments

  • Screen Shot 2012-05-04 at 18.02.18.png
    Screen Shot 2012-05-04 at 18.02.18.png
    32.8 KB · Views: 233
This codeis trying to call a method that doesn't exist:
Code:
    [alert beginSheetModalForWindow:[self windowForSheet]
                      modalDelegate:self];
There is no such method in NSAlert. You may well believe there is such a method, so please point to a reference that shows this method in use, as you've used it.

I suggest reading the class reference doc. There is a method whose name begins like your code, but it has two additional parameters and a longer name.

This is not a framework problem, nor can it be fixed by tweaking imports. You must change your code, so it calls the method that exists, using the exact name shown in the reference doc, and supplying all necessary parameters.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.