• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
-[NSWindow parentWindow] for sheet never works?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-[NSWindow parentWindow] for sheet never works?


  • Subject: -[NSWindow parentWindow] for sheet never works?
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 24 Nov 2015 08:47:38 -0800

I’m updating an old project which used the -[NSApp beginSheet:::::] methods to use -[NSWindow beginSheet:completionHandler:].  In so doing, I now need the parent window in my action methods, so I can send the -[NSWindow endSheet::] message which runs the completion handler.  In many cases, the sheet is handy but the parent window is not.  No problem, I thought, just use send -[NSWindow parentWindow] to the sheet.

Unfortunately this always returns nil, unless I set is using -[NSWindow setParentWindow:] beforehand, which the documentation and common sense says is unnecessary.

Is the non-functioning of -[NSWindow parentWindow] a known bug, or am I doing something wrong?

I have reproduced the problem in a demo project which and put it on github.com (links below).  Here is the code:

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSWindow *sheet;

@end

@implementation AppDelegate

- (IBAction)showSheet:(id)sender {
    [self.window beginSheet:self.sheet
     completionHandler:^void(
                             NSModalResponse modalResponse) {
         NSLog(@"Got response: %ld", modalResponse) ;
     }] ;
}

- (IBAction)done:(id)sender {
    NSWindow* parentWindow = [self.sheet parentWindow] ;
    if (!parentWindow) {
        NSLog(@"Nil parentWindow!  Workaround being used") ;
        parentWindow = self.window ;
    }
    [parentWindow endSheet:self.sheet
                returnCode:123] ;
}

@end


Project: https://github.com/jerrykrinock/SheetDemo
Clone:  https://github.com/jerrykrinock/SheetDemo.git
_______________________________________________

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


  • Follow-Ups:
    • Re: -[NSWindow parentWindow] for sheet never works?
      • From: Graham Cox <email@hidden>
    • Re: -[NSWindow parentWindow] for sheet never works?
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Swift - internal class conforming to public protocol
  • Next by Date: Re: Swift - internal class conforming to public protocol
  • Previous by thread: Re: Swift - internal class conforming to public protocol
  • Next by thread: Re: -[NSWindow parentWindow] for sheet never works?
  • Index(es):
    • Date
    • Thread