 |
 |
Sheets
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
I'd like to comply by Apple's Interface guidelines. That means that I'd have to use sheets on occasion. The only problem that I have is that sheets are poorly documented and there is no sample code. I have a few questions. First in NSApp, for the method
- (void)beginSheet  NSWindow *)sheet modalForWindow  NSWindow *)docWindow modalDelegate  id)modalDelegate didEndSelector  SEL)didEndSelector contextInfo  void *)contextInfo
What is a modal delegate and what is context info? I have been able to make a sheet appear by passing it the window that I want as a sheet, the window that it was modal to, self as the modal delegate and NULL for the rest. However, I can't get rid of the sheet.
- (void)endSheet  NSWindow *)sheet
, from NSApp doesn't work. The sheet stays there. I don't get an error. If I pass it a selector for a method in the calling class it does seem to execute it when I use endSheet, the only problem is that the sheet doesn't go away! Can anyone explain how to make a simple sheet appear and then make it go away. I'm sure there are others who would like to abide by the interface guidelines as much as me who know nothing about sheets.
[This message has been edited by Dalgo (edited 01-21-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status:
Offline
|
|
WHY SO SAD?
Cheer up!
heheh, really, as a senior member, you should know how to turn of smiles!
[This message has been edited by Kristoff (edited 01-21-2001).]
[This message has been edited by Kristoff (edited 01-21-2001).]
|
|
signatures are a waste of bandwidth
especially ones with political tripe in them.
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
Oops! I didn't think about it. Now it's fixed. Be happy. 
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: San Jose, CA USA
Status:
Offline
|
|
Sheets are actually pretty simple to use in AppKit.
- (void)beginSheet  NSWindow *)sheet modalForWindow  NSWindow *)docWindow modalDelegate  id)modalDelegate didEndSelector  SEL)didEndSelector contextInfo  void *)contextInfo
The modalDelegate is simply the object that should be messaged when the sheet goes away, and the didEndSelector is the message to send to that object. If you look in NSWindow.h where this declaration comes from (or is it NSPanel.h?) there is a comment showing what the parameters to the didEndSelector should look like. Finally, the contextInfo is exactly like the "refCon" in the classic Mac Toolbox -- it's for your own use and gets passed to the delegate. If you don't need it, just pass NULL.
I've implemented many sheets and haven't had any trouble with them not going away, so I'm not sure what to say about that. Are you dismissing the sheet from within a message called by the kit? Typically it's the action message of a button. That's how I do it. Make double sure that you are actually passing a pointer to the sheet window.
[This message has been edited by Mooseyard (edited 01-22-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status:
Offline
|
|
Thanks. Being able to tell it to do different methods when it is done is useful. Since sheets are just windows that are handled differently I thought that I'd try something like [sheet orderOut:nil]; to get rid of my sheet. It worked. I wonder why [sheet endSheet]; doesn't get rid of the sheet. I found that I still have to call it even if I use orderOut. When I didn't call it, the program quit when it was supposed to display the sheet a second time.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by Dalgo:
The only problem that I have is that sheets are poorly documented and there is no sample code.
I don't know if you found these resources, but on Public Beta, there is some sheet info in the AppKit release notes:
/Developer/Documentation/ReleaseNotes/AppKitPrePublicBeta.html
and the TextEdit example has some significant sheet usage (it puts up a bunch of sheets in some cases, one after another):
/Developer/Examples/AppKit/TextEdit
Ali
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Can someone post what the didEndSector: argument might actually look like for trying to run a sheet. I am a novice.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by macrophyllum:
Can someone post what the didEndSector: argument might actually look like for trying to run a sheet. I am a novice.
In TextEdit, the save sheet is put up at one point:
[panel beginSheetForDirectory:... file:... modalForWindow:... modalDelegate:... didEndSelector:@selector(didEndSaveSheet:returnCod e:contextInfo contextInfo:docInfo];
The actual method implementation corresponding to that selector is:
- (void)didEndSaveSheet NSSavePanel *)savePanel returnCode int)returnCode contextInfo void *)contextInfo {
...
}
The above example is for NSSavePanel, but it works in the generic sheet case as well (sheets you put up with NSApplication's beginSheet: ... ). Basically, the didEndSelectors take three arguments: One for the sheet, one for the return code, and one for the contextInfo which is blindly passed around for your benefit.
Ali
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
So say I want to use didEndSelector: to send a method that normally is called by (IBAction). Is there a way to do this? Right now I have:
[myPanel beginSheet:helpWindow modalForWindow:myPanel modalDelegate:self didEndSelector:@selector(resumeTime  contextInfo:NULL];
//where myPanel is the window on which the sheet helpWindow slides down
//here is the resumeTime method:
- (IBAction)resumeTime  id)sender {
aTimer = [NSTimer scheduledTimerWithTimeInterval: 10
target:self
selector:@selector(displayTime 
userInfo:nil
repeats:YES];
message = @"At Work";
[stateField setStringValue: message];
}
//And I get the following error: -[NSPanel beginSheet:modalForWindow:modalDelegate:didEndSele ctor:contextInfo:]: selector not recognized
Anyone have any suggestions. I have played around with putting in different arguments for the "didEndSelector:" and I always seem to get the same error.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
And I get the following error: -[NSPanel beginSheet:modalForWindow:modalDelegate:didEndSele ctor:contextInfo:]: selector not recognized
This problem is because NSPanel does indeed not have a beginSheet:... method. This method, beginSheet:..., is in NSApplication. See NSApplication.h.
As far as your other issue of wanting to call resumeTime: when the sheet ends --- can't directly do that; the method has to have the signature we discussed earlier. That is, it can be named anything you want, but it has to have the three arguments --- sheet, return code, and contextInfo, and the same return type, which is void I think.
But, this is no big deal: You can implement such a method, and call resumeTime: from that. You can use the returnCode to see how the panel was dismissed, if you wish; or you can ignore all the arguments.
Ali
[This message has been edited by ali (edited 05-30-2001).]
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Thanks for practically walking me through this Ali. I have one (hopefully last) question:
To use the beginSheet: method, do I just declare an (NSApplication *anApplication); in the header file where I declare other objects and then call the beginSheet method from anApplication? I did this and I didn't get any run time errors, but no sheet appeared? Any suggestions?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
Originally posted by macrophyllum:
To use the beginSheet: method, do I just declare an (NSApplication *anApplication); in the header file where I declare other objects and then call the beginSheet method from anApplication? I did this and I didn't get any run time errors, but no sheet appeared? Any suggestions?
Every Cocoa app has a single instance of NSApplication, which is accessible via [NSApplication sharedApplication]. You should send any NSApplication messages to that instance, so
[[NSApplication sharedApplication] beginSheet: ... ];
Ali
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status:
Offline
|
|
Thanks Ali! Works great now and I have learned a lot from you.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|