我有一个显示模态的 NSWindow/Controller。它有一个“关闭”按钮连接到这样的操作:
- (IBAction)close:(id)sender
{
[self.window orderOut:sender];
[self.window close];
[[NSApplication sharedApplication] stopModal];
}
在我的主窗口中,我显示了模式:
- (IBAction)modal:(id)sender
{
NSLog(@"Before: %lu", [[[NSApplication sharedApplication] windows] count]);
ModalWindowController *modal = [[ModalWindowController alloc] initWithWindowNibName:@"ModalWindowController"];
[[NSApplication sharedApplication] runModalForWindow:modal.window];
NSLog(@"After: %lu", [[[NSApplication sharedApplication] windows] count]);
}
我打开和关闭模态几次,输出是这样的:
2013-01-17 14:36:08.071 Modals[3666:303] Before: 1
2013-01-17 14:36:08.962 Modals[3666:303] After: 2
2013-01-17 14:36:09.578 Modals[3666:303] Before: 2
2013-01-17 14:36:11.009 Modals[3666:303] After: 3
2013-01-17 14:36:12.108 Modals[3666:303] Before: 3
2013-01-17 14:36:12.910 Modals[3666:303] After: 4
因此,[[[NSApplication sharedApplication] windows] count]只会增加。
我希望它随着我打开和关闭模式窗口而增加和减少。我的应用程序使用 ARC。谁可以给我解释一下这个?
先感谢您