我创建了一个NSWindow
self.storeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 800, 660) styleMask:NSWindowStyleMaskResizable|NSWindowListOrderedFrontToBack|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:false];
[self.storeWindow setDelegate:self];
打开和关闭均正确。但是,如果我再次致电甚至检查是否为零,它会因EXC_BAD_ACCESS崩溃。
我在标头中将其声明为字符串属性
@property (strong,nonatomic) NSWindow *storeWindow;
if (self.storeWindow.contentView == nil) {
self.storeWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 100, 800, 660) styleMask:NSWindowStyleMaskResizable|NSWindowListOrderedFrontToBack|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:false];
[self.storeWindow setDelegate:self];
}
[self.storeWindow setBackgroundColor:[NSColor whiteColor]];
self.store = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 850, 640)];
[self.store loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:json[@"url"]]]];
[self.storeWindow.contentView addSubview:self.store];
[self.storeWindow makeKeyAndOrderFront:self.window];
有什么想法吗?
答案 0 :(得分:0)
NSWindow的releasedWhenClosed属性设置为更改默认行为,即关闭窗口时释放窗口(除非它由窗口控制器拥有)。该属性可以在“界面编辑器”的“属性”检查器中设置,也可以通过编程方式设置,例如:
[myWindow setReleasedWhenClosed:NO];