作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下代码来工作。它第一次执行预期的操作,打开一个窗口并将其设为前窗口,但是当随后调用它时, orderFront: 不起作用,因为 window 为 nil。为什么 initWithWindowNibName:
不设置从 initWithNibName:
返回的 NSWindowController
对象的窗口字段?
//
// CustomerCard.m
// POSWonder
//
// Created by kaydell on 2/26/12.
// Copyright 2012 Kaydell Leavitt. All rights reserved.
//
#import "CustomerCard.h"
@implementation CustomerCard
// declare customerCard as a static variable
static CustomerCard* customerCard;
+(void) show {
// if the customer card isn't instantiated, then instantiate it
if (customerCard == nil) {
customerCard = [[CustomerCard alloc] initWithWindowNibName:@"CustomerCard"];
if (!customerCard.window) {
NSLog(@"Why is window nil here?"); // <<<<<<<<<<< This line gets called <<<<<
}
}
// show the customer card and make it the front window
[customerCard showWindow:self];
[customerCard.window orderFront:self]; // <<<<<<<< This line doesn't seem to do anything
}
-(void) dealloc {
customerCard = nil;
[super dealloc];
}
@end
最佳答案
在 Interface Builder 中,您需要取消选中标有“关闭时释放”的框。如果启用此复选框,窗口将被释放,并可能在关闭时被释放。
如果您想保留窗口,您不希望出现这种行为,因此您需要将其关闭。
关于cocoa - 不 initWithWindowNibName 设置窗口字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9969394/
我正在尝试使用以下代码来工作。它第一次执行预期的操作,打开一个窗口并将其设为前窗口,但是当随后调用它时, orderFront: 不起作用,因为 window 为 nil。为什么 initWithWi
我想知道的是我用的窗口 Controller 是如何初始化的 NSWindowController *c=[[NSWindowController alloc] initWithWindowNibNa
我想做的是创建一个打开窗口的对象的方法。在此窗口中,我想输出对象实例的一些属性。为此,我创建了 NSObject 的“Profile”子类,它有一个名为“view”的 NSWindowControll
我是一名优秀的程序员,十分优秀!