Sheet Doesn't Attach Itself To Window

  • Hello,

    I'm trying to display a sheet in Leopard but I've run into a peculiar
    situation, for which I cannot find anyone who has shared a similar
    experience. I can display a sheet but it is not attached to the
    window. When the sheet appears (i.e. it just shows up, no animation)
    it is properly centered on its window. I can click on the title bar of
    the owner window and move that window around but the sheet remains in
    its original location. If anyone could advise me on how to correct the
    problem, I'd greatly appreciate it.

    I call NSApp's
    beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
    method. I've verified that no nil values, other than contextInfo are
    being passed to the method. The code that displays the sheet is as
    follows:

    [NSApp beginSheet:self.sheetWindowController.window
      modalForWindow:self.window
        modalDelegate:self
        didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
          contextInfo:nil];
    [NSApp runModalForWindow:self.sheetWindowController.window];

    The sheetWindowController property's body is as follows. Note that
    sheetWindowController is an instance variable.

    if (sheetWindowController == nil)
    {
    sheetWindowController = [[SheetWindowController alloc] init];

    if (editStudentWindowController == nil)
    {
      NSLog(@"Failed to load the nib file \"TheSheet\"");
    }
    }

    return editStudentWindowController;

    The init method for SheetWindowController loads the nib file with the
    following code:

    - (id)init
    {
    if ((self = [super initWithWindowNibName:@"TheSheet"]))
    {
      // TODO: Add code once this starts working!
    }

    return self;
    }

    The nib files seem to be wired up properly and the code seems to load
    everything properly as the sheet does actually appear, just not
    attached to the window.

    If someone could point out my error or advise me to more advanced
    debugging techniques to find the error, I would greatly appreciate it.

    Thanks in advance,
    Brian
  • >
    > [NSApp beginSheet:self.sheetWindowController.window
    > modalForWindow:self.window
    > modalDelegate:self
    > didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
    > contextInfo:nil];
    > [NSApp runModalForWindow:self.sheetWindowController.window];
    >

    What you are doing here is first begin a sheet for you sheetWindow,
    and directly after that you start a modal session for the same window
    (see the docs for the distinction between a sheet and a modal window).
    If you remove the second method call, everything should be fine.

    Cheers, Patrick
  • >> [NSApp beginSheet:self.sheetWindowController.window
    >> modalForWindow:self.window
    >> modalDelegate:self
    >> didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
    >> contextInfo:nil];
    >> [NSApp runModalForWindow:self.sheetWindowController.window];
    >>
    >
    > What you are doing here is first begin a sheet for you sheetWindow,
    > and directly after that you start a modal session for the same
    > window (see the docs for the distinction between a sheet and a modal
    > window). If you remove the second method call, everything should be
    > fine.

    Thanks for your reply. Originally I didn't call runModalForWindow: and
    in this case the sheet was still not attached to the window. Because I
    was not calling it, it was possible for the user to drag the window to
    a different location. If this event happens, the sheet remains in its
    original position where it was initially shown and the controls in the
    owning window still respond to events with the sheet displayed
    elsewhere on the screen! Calling this method was just a workaround
    disabling the for the still responsive sheet owning window.
  • > The sheetWindowController property's body is as follows. Note that
    > sheetWindowController is an instance variable.
    >
    > if (sheetWindowController == nil)
    > {
    > sheetWindowController = [[SheetWindowController alloc] init];
    >
    > if (editStudentWindowController == nil)
    > {
    > NSLog(@"Failed to load the nib file \"TheSheet\"");
    > }
    > }
    >
    > return editStudentWindowController;

    Ok, now I had a look at the rest of your code: is the use of both
    "sheetWindowController" and "editStudentWindowController" deliberate?

    Patrick
  • No, sorry, that was a typo. editStudentWindowController should be
    renamed to sheetWindowController. That was an oversight in stripping
    out all the irreverent code and I apologize.

    Brian

    On Nov 28, 2007, at 3:49 PM, PGM wrote:

    > Ok, now I had a look at the rest of your code: is the use of both
    > "sheetWindowController" and "editStudentWindowController" deliberate?
  • Hello all,

    I have some new information that may be relevant. Now that I've
    removed the runModalForWindow: method, I can display the sheet after
    it has been dismissed. When I initially display the sheet, it is still
    not attached to the window and still not modal for the window.
    However, on subsequent shows its works properly. Any ideas on why the
    first run doesn't work correctly?

    Thanks in advance,
    Brian

    On Nov 28, 2007, at 2:53 PM, Brian T. Kelley wrote:

    > Hello,
    >
    > I'm trying to display a sheet in Leopard but I've run into a
    > peculiar situation, for which I cannot find anyone who has shared a
    > similar experience. I can display a sheet but it is not attached to
    > the window. When the sheet appears (i.e. it just shows up, no
    > animation) it is properly centered on its window. I can click on the
    > title bar of the owner window and move that window around but the
    > sheet remains in its original location. If anyone could advise me on
    > how to correct the problem, I'd greatly appreciate it.
    >
    > I call NSApp's
    > beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
    > method. I've verified that no nil values, other than contextInfo are
    > being passed to the method. The code that displays the sheet is as
    > follows:
    >
    > [NSApp beginSheet:self.sheetWindowController.window
    > modalForWindow:self.window
    > modalDelegate:self
    > didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
    > contextInfo:nil];
    > //[NSApp runModalForWindow:self.sheetWindowController.window];
    >
    >
    > The sheetWindowController property's body is as follows. Note that
    > sheetWindowController is an instance variable.
    >
    > if (sheetWindowController == nil)
    > {
    > sheetWindowController = [[SheetWindowController alloc] init];
    >
    > if (sheetWindowController == nil)
    > {
    > NSLog(@"Failed to load the nib file \"TheSheet\"");
    > }
    > }
    >
    > return editStudentWindowController;
    >
    > The init method for SheetWindowController loads the nib file with
    > the following code:
    >
    > - (id)init
    > {
    > if ((self = [super initWithWindowNibName:@"TheSheet"]))
    > {
    > // TODO: Add code once this starts working!
    > }
    >
    > return self;
    > }
    >
    > The nib files seem to be wired up properly and the code seems to
    > load everything properly as the sheet does actually appear, just not
    > attached to the window.
    >
    > If someone could point out my error or advise me to more advanced
    > debugging techniques to find the error, I would greatly appreciate it.
    >
    > Thanks in advance,
    > Brian
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today