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
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'?
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.
'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.
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:
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.
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).
Replies
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:
and pass that "docWindow" to beginSheetModalForWindow method.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI've now got:
Which I call in:
- (void)windowControllerDidLoadNib:(NSWindowController *) aController {[self showNewUserMessage];
}
My header file has these imports in addition to what I posted previously:
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:
And I get this yellow error in Xcode:
(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
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThis is from NSAlert help:
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).
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome