質問

I have a relatively-lengthy task. So I bring up a separate window (NSWindowController) from AppDelegate to show progress. It goes like

//AppDelegate.m
if (self.progresswindow == nil) {
    self.progresswindow = [[ProgressController alloc] initWithWindowNibName:@"ProgressController"];
}

[progresswindow showWindow:self];
//[[progresswindow window] setReleasedWhenClosed:NO];
[NSApp runModalForWindow:progresswindow.window];

When a task is complete, the progress window will close itself.

//ProgressController.m
[NSApp stopModal];
[self close];

It works fine. But when I click on a button to start another session of a task with the same window, the application won't run a task although it opens. It appears that the last instance hasn't be released. The progress window has the following lines.

- (void)windowDidLoad {
    NSLog(@"Hey!");
}

And NSLog won't be called for the 2nd time. I wonder what I'm doing wrong? Calling setReleasedWhenClosed from AppDelegate has no effect. I have the Release When Closed checkbox enabled, anyway. I read something like I need to observe NSWindowWillCloseNotification the progress window in a different topic so that I can release it when it closes. But I'm using ARC. So I can't manually release it, can I? Meanwhile, if I open Apple's sample (TableViewPlayground), it seems that they use this notification. Furthermore, I've read this topic and this topic. But I don't know what the problem is.

I appreciate any advice. Thank you for your time.

役に立ちましたか?

解決

Release the Progress-Window-Controller.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top