Re: self Changes on Open Panel
Re: self Changes on Open Panel
- Subject: Re: self Changes on Open Panel
- From: "K. Darcy Otto" <email@hidden>
- Date: Tue, 9 Jun 2009 15:50:15 -0700
Hi Greg,
Thanks for your suggestions. I got some (to me) surprising results.
Here is the code:
//////////// Code
//////////// From MyDocument.h:
@interface MyDocument : NSDocument
{
BOOL sheetOpen; // sheetOpen must be accessed directly; there are no
accessors
... other stuff ...
}
//////////// Code
//////////// From MyDocument.m:
-(void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[self performSelector:@selector(openConclusionSheetForWindow:)
withObject:[deductionTable window] afterDelay:0.1];
... other stuff ...
}
-(void)openConclusionSheetForWindow:(NSWindow *)window
{
NSLog(@"sheetOpen before NSApp beginSheet: %d",sheetOpen);
// Launch conclusion sheet
[NSApp beginSheet:[conclusionController window] modalForWindow:window
modalDelegate:self didEndSelector:NULL contextInfo:NULL];
NSLog(@"sheetOpen after NSApp beginSheet: %d",sheetOpen);
}
-(void)windowWillBeginSheet:(NSNotification *)notification
{
NSLog(@"sheetOpen an -windowWillBeginSheet start: %d",sheetOpen);
sheetOpen = YES;
NSLog(@"sheetOpen an -windowWillBeginSheet end: %d",sheetOpen);
}
- (void)windowDidEndSheet:(NSNotification *)notification
{
NSLog(@"sheetOpen an -windowDidEndSheet start: %d",sheetOpen);
sheetOpen = NO;
NSLog(@"sheetOpen an -windowDidEndSheet end: %d",sheetOpen);
}
-(BOOL)validateUserInterfaceItem:(id
<NSValidatedUserInterfaceItem>)anItem
{
NSLog(@"sheetOpen at validateUserInterfaceItem: %d",sheetOpen);
... validation stuff ...
}
And here is the output (my "**"):
sheetOpen at validateUserInterfaceItem: 0
sheetOpen before NSApp beginSheet: 0
sheetOpen an -windowWillBeginSheet start: 0
sheetOpen an -windowWillBeginSheet end: 1
sheetOpen after NSApp beginSheet: 1 **
sheetOpen at validateUserInterfaceItem: 0
sheetOpen an -windowDidEndSheet start: 1 **
sheetOpen an -windowDidEndSheet end: 0
sheetOpen at validateUserInterfaceItem: 0
The lines marked ** surprise me; I had expected they would be zero as
well. If I replace these NSLogs with requests to display self, I get
(again, my "**"):
self at validateUserInterfaceItem: <MyDocument: 0x1047180>
self before NSApp beginSheet: <MyDocument: 0x1047180>
self at -windowWillBeginSheet: <MyDocument: 0x1047180>
self after NSApp beginSheet: <MyDocument: 0x1047180>
self at validateUserInterfaceItem: <MyDocument: 0x102d430> **
self at -windowDidEndSheet: <MyDocument: 0x1047180>
self at validateUserInterfaceItem: <MyDocument: 0x1047180>
Bizarreness at **! I mean, -init is only run once!
(I'll answer your question in the next message; I know there is a
limit to message lengths on the list, so I'll break it up.) Thanks
again.
On 9-Jun-09, at 10:12 AM, Greg Guerin wrote:
K. Darcy Otto wrote:
-(void)windowWillBeginSheet:(NSNotification *)notification
{
sheetOpen = YES;
NSLog(@"self at -windowWillBeginSheet: %@",self);
}
I would NSLog the before and after state of sheetOpen, i.e. on entry
to the method body and on exit from the method body. I might even
consider assertions.
Please show the code that defines the sheetOpen class variable, and
identify exactly where it resides (which class), and how other
classes have access to it. I mention this because all the behavior
you've described so far is consistent with what happens if sheetOpen
isn't actually a class variable or a static variable, but is an
instance variable.
Finally, please explain what problem you're trying to solve by
having a boolean sheetOpen class variable. Is this related to your
earlier "How to tell if a Panel is Open" question? If so, please
explain the premise of that question: you wrote, "I need to know
whether a particular panel is open", but never explained why you
need to know that, or what you'd do with that state.
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden