Re: Close Modal window after sheet ends

2015-08-24 Thread Quincey Morris
On Aug 24, 2015, at 11:00 , Alex Kac  wrote:
> 
> As for the relevant window properties - i’m not setting any. What would I set 
> to nil? I’m not setting delegate (you can see 100% of the code below - its 
> literally just getting the window controller, and then setting the window 
> controller to nil when its done.

The window controller itself may set either or both of the “delegate” and 
“windowController” properties, both of which are unowned (i.e.weak) references 
and therefore dangerous at the end of the window controller life cycle. If 
setting the window controller to nil causes it to be deallocated, you could be 
heading for a crash.

If you explicitly order out the sheet, I think that will (as a side effect) 
cause sheet window’s “windowController” property to be set to nil for you, but 
I don’t think the delegate ever gets cleared automatically.

On Aug 24, 2015, at 10:53 , Alex Kac  wrote:
> 
>   if (returnCode == 1)
>   {
>   quitMeansCloseWindow = YES;
>   dispatch_async(dispatch_get_main_queue(), ^{
>   NSLog(@“Do I get called?”);
>   });
>   }

This make it look like there’s something else wrong. I don’t think a modal 
window should block the main queue.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Close Modal window after sheet ends

2015-08-24 Thread Ken Thomases
On Aug 24, 2015, at 12:53 PM, Alex Kac  wrote:
> 
> I’ve also tried this…and the code in the dispatch_async never gets called. 
> I’ve seen other code on github that does something similar so obviously it 
> *should* work.
> 
> - (IBAction)enterRegCode:(id)sender {
>   
>   registrationWindowController = [[RegistrationWindow alloc] 
> initWithWindowNibName:@"RegistrationWindow"];
>   
>   __weak PIIntroWindowController* weakSelf = self;
>   
>   [self.window beginSheet:registrationWindowController.window 
> completionHandler:^(NSModalResponse returnCode) {
>   registrationWindowController = nil;
> 
>   if (returnCode == 1)
>   {
>   quitMeansCloseWindow = YES;
>   dispatch_async(dispatch_get_main_queue(), ^{
>   NSLog(@“Do I get called?”);
>   });
>   }
>   
>   }];
> 
> }

Have you tried logging returnCode above the "if"?  The obvious reason that your 
log statement would not run is that returnCode is not 1.

Regards,
Ken


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Close Modal window after sheet ends

2015-08-24 Thread Quincey Morris
On Aug 24, 2015, at 10:41 , Alex Kac  wrote:
> 
>   registrationWindowController = [[RegistrationWindow alloc] 
> initWithWindowNibName:@"RegistrationWindow"];
>   
>   [self.window beginSheet:registrationWindowController.window 
> completionHandler:^(NSModalResponse returnCode) {
>   registrationWindowController = nil;
> 
>   if (returnCode == 1)
>   {
>   [[NSApplication sharedApplication] stopModal];
>   [self.window close]; 
>   //[self.window orderOut:nil]
>   }
>   }];

At the very least, you should order out the sheet (inside the if block) before 
doing anything to the window underneath.

Also, though probably unrelated to the current behavior, you probably shouldn’t 
simply nil out the sheet window controller reference like that. Doing so can 
(and I think always will) leave a dangling invalid pointers from the window — 
the “windowContoller” and “delegate” properties, for example. You should first 
set the relevant window properties to ni

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Close Modal window after sheet ends

2015-08-24 Thread Alex Kac
I’ve also tried this…and the code in the dispatch_async never gets called. I’ve 
seen other code on github that does something similar so obviously it *should* 
work.

- (IBAction)enterRegCode:(id)sender {

registrationWindowController = [[RegistrationWindow alloc] 
initWithWindowNibName:@"RegistrationWindow"];

__weak PIIntroWindowController* weakSelf = self;

[self.window beginSheet:registrationWindowController.window 
completionHandler:^(NSModalResponse returnCode) {
registrationWindowController = nil;

if (returnCode == 1)
{
quitMeansCloseWindow = YES;
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@“Do I get called?”);
});
}

}];

}


> On Aug 24, 2015, at 11:41 AM, Alex Kac  wrote:
> 
> I’ve got a modal window which opens a sheet to let the user enter a 
> registration code. If the Reg code is accepted, I want to close the window 
> after the sheet ends. However it doesn’t. I’ve tried a ton of different 
> things and I believe it has something to do with the runLoop because dispatch 
> timers, async, etc… do not work in the completionHandler at all. Neither does 
> performSelector:afterDelay:. Nothing that seems to use a timer works. 
> 
> Here is how I present the main window:
> [[NSApplication sharedApplication] 
> runModalForWindow:introSheetController.window];
> 
> and then when the user selects “Enter Registration Code”:
> 
> - (IBAction)enterRegCode:(id)sender {
>   
>   registrationWindowController = [[RegistrationWindow alloc] 
> initWithWindowNibName:@"RegistrationWindow"];
>   
>   [self.window beginSheet:registrationWindowController.window 
> completionHandler:^(NSModalResponse returnCode) {
>   registrationWindowController = nil;
> 
>   if (returnCode == 1)
>   {
>   [[NSApplication sharedApplication] stopModal];
>   [self.window close]; 
>   //[self.window orderOut:nil]
>   }
>   }];
> }
> 
> What do you think? I think I know what’s wrong, but I’ve tried enough things 
> that don’t work that I’m sure its something basic and simple.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com