Re: Cocoa-dev Digest, Vol 12, Issue 656
Re: Cocoa-dev Digest, Vol 12, Issue 656
- Subject: Re: Cocoa-dev Digest, Vol 12, Issue 656
- From: Michael Domino <email@hidden>
- Date: Wed, 25 Nov 2015 12:27:08 +0000
- Thread-topic: Cocoa-dev Digest, Vol 12, Issue 656
Graham,
You said, "you close the sheet itself by sending -endSheet to the SHEET, not its parent”. Correct me if I am wrong, but I think you send endSheet: to the parent window, with the sheet window to be dismissed a parameter. Same for the deprecated NSApp method of the same name.
The doc says:
- endSheet:
Ends a document-modal session and dismisses the specified sheet.
Declaration
OBJECTIVE-C
- (void)endSheet:(NSWindow *)sheetWindow
Parameters
sheetWindow
The window object that represents the sheet to be dismissed.
Best,
Michael
>
> Message: 1
> Date: Wed, 25 Nov 2015 09:54:03 +1100
> From: Graham Cox <email@hidden>
> To: Jerry Krinock <email@hidden>
> Cc: Cocoa Developers <email@hidden>
> Subject: Re: -[NSWindow parentWindow] for sheet never works?
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=utf-8
>
>
>> 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