Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Can't Display NSAlert - Use of Undeclared Identifier

gwelmartengwelmarten Posts: 15Registered Users
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:

Use of undeclared identifier 'window'; did you mean '_windows'?

My code for displaying the NSAlert is:

- (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:
#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
Post edited by gwelmarten on

Replies

  • nestochinestochi Posts: 44Registered Users
    'window' is not the view, is the window of the application where you want the sheet to appear.


    You don't say where you're invoking that method from, but if you are calling that from your document class, NSDocument has a method to get the proper window. "windowForSheet"

    From your document class, do something like this:
    id docWindow = [self windowForSheet];


    and pass that "docWindow" to beginSheetModalForWindow method.
  • gwelmartengwelmarten Posts: 15Registered Users
    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:

    - (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:

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


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

    #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:

    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:

    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
    Screen Shot 2012-05-04 at 18.02.18.jpg
    1 x 1 - 4K
  • nestochinestochi Posts: 44Registered Users
    it seems that you missed some parameters when you invoke beginSheetModalForWindow.
    This is from NSAlert help:

    beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:
    Runs the receiver modally as an alert sheet attached to a specified window.

    - (void)beginSheetModalForWindow:(NSWindow *)window modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(void *)contextInfo



    In your code you are not passing the didEndSelector nor contextInfo, so you're getting an exception because that method does not exists (xcode warned you about it).
Sign In or Register to comment.