Re: -[NSWindow parentWindow] for sheet never works?
Re: -[NSWindow parentWindow] for sheet never works?
- Subject: Re: -[NSWindow parentWindow] for sheet never works?
- From: Graham Cox <email@hidden>
- Date: Wed, 25 Nov 2015 09:54:03 +1100
> On 25 Nov 2015, at 3:47 AM, Jerry Krinock <email@hidden> wrote:
>
> ’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?
Hi Jerry,
You don’t send the parent window endSheet to run the completion handler - you close the sheet itself by sending -endSheet to the SHEET, not its parent. If you need to communicate something back to the parent window or code that ran the sheet, just do it directly from the completion handler. As a block, it can capture variables from its initiating scope. It’s all far easier than the old approach.
—Graham
_______________________________________________
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