NSWindowController 和 isWindowLoaded

发布于 2024-09-02 01:35:37 字数 510 浏览 2 评论 0原文

我有一个 NSWindowController,我像这样初始化它;

+ (MyWindowController *) sharedController
{
    static MyWindowController *singleton = nil;

    if (!singleton) singleton = [[self alloc] initWithWindowNibName: @"myWindow"];
    return singleton;
}

我展示这样的窗口;

[[MyWindowController sharedController] showWindow: nil];

现在的问题是我需要来自该窗口上的某些控件的信息。但如果窗口尚未加载,我不想加载窗口,因为这样我就可以使用默认值。我应该使用 isWindowLoaded 吗? @property 访问单例?或者这里推荐什么? (如果@property,那么也请给我只读的非原子属性。)

I have an NSWindowController and I initialize it like this;

+ (MyWindowController *) sharedController
{
    static MyWindowController *singleton = nil;

    if (!singleton) singleton = [[self alloc] initWithWindowNibName: @"myWindow"];
    return singleton;
}

and I show windows like this;

[[MyWindowController sharedController] showWindow: nil];

Now the problem is that I need information from some controls on that window. But I do not want to load the window if it's not yet loaded because then I can just go with the defaults. Should I use isWindowLoaded? @property to access the singleton? or what is recommended here? (If @property, then please give me the readonly, nonatomic attributes too.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拿命拼未来 2024-09-09 01:35:37

不要将模型数据存储在视图中。让控制器(可能不是 MyWindowController,而是需要数据的控制器)拥有真实数据(如果有)并填写任何默认值。

您在 Interface Builder 中填写的任何值都应该仅用于调整大小。

例如,如果我知道某个字段必须保存值为 ±50000 的数字,我将输入“-50000”并相应地调整字段大小,然后将“-50000”保留在那里。实际的默认值更有可能是 0 或其他值,我将拥有该值的控制器提供的值(或者,如果该字段显示模型对象的属性,我将拥有每个新模型提供的默认值目的)。

Don't store model data in views. Have the controller (probably not MyWindowController, but the one that needs the data) own the real data (if any) and fill in any defaults.

Any values you fill in in Interface Builder should be for nothing more than sizing.

For example, if I know a field must hold a number whose value is ±50000, I'll enter “-50000” and size the field accordingly, and leave the “-50000” there. The actual default is more likely to be 0 or something, and I will have that provided by the controller that owns the value (or, if the field shows a property of a model object, I'll have the default provided by each new model object).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文