当 NSViewController 重新加载时,使用文件中的新数据重绘 NSTableView?

发布于 2024-10-18 20:06:07 字数 1502 浏览 7 评论 0原文

我有一个基于 Mac OS X 文档的应用程序,它有多个 NSViewController,我可以在它们之间切换,并且每个视图根据先前 NSViewController 的 NSTableView 中的用户选择显示 NSTableView 中 plist 文件的数据。我遇到的问题是,我无法弄清楚每次加载 NSViewController 时可以调用什么函数,以从文件中读取正确的数据以在 NSTableView 中显示。对于UIViewControllers我使用了viewDidLoad、viewWillAppear等函数族,但是我一直没能找到NSViewController对应的函数。

目前我正在使用 awakeFromNib,它工作正常,但仅限于第一次加载 NSViewController 时。我尝试过 loadView,但这会折叠 NSView。我认为我需要做更多设置才能使用 loadView。

我正在使用 Hillegass 的《Cocoa Programming for MAC OS X》一书中的视图交换代码,该代码使用以下代码切换视图控制器:

  - (void)displayViewController:(ManagingViewController *)vc
                   curBox: (NSBox *)windowBox

  {
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
    NSBeep();
    return;
}
NSView *v = [vc view];

NSSize currentSize = [[windowBox contentView] frame].size;

NSSize newSize = [v frame].size;

float deltaWidth  = newSize.width  - currentSize.width;
float deltaHeight = newSize.height - currentSize.height;

NSRect windowFrame = [w frame];
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;

[windowBox setContentView:nil];
[w setFrame:windowFrame
    display:YES
    animate:YES];

[windowBox setContentView:v];

// Put the view controller in the responder chain

[v setNextResponder:vc];
[vc setNextResponder:windowBox];
 }

并将 NSView 控制器放入响应者链中。

每次交换 NSViewController 时是否可以调用一些函数来设置视图?我可以检查 NSViewController 是否已成为第一个响应者吗?

I have a Mac OS X Document based app that has multiple NSViewControllers that I switch between and each view displays data from plist files in NSTableViews based on the user selections in the previous NSViewController's NSTableView. The problem I have is that I can't figure out what function can be called, every time a NSViewController gets loaded, to read the correct data from a file to display in the NSTableView. For UIViewControllers I used the function family of viewDidLoad, viewWillAppear, but I haven't been able to find the corresponding functions for NSViewController.

Currently I am using awakeFromNib, which works fine, but only the first time the NSViewController gets loaded. I've tried loadView, but that collapses the NSView. I assume that I need to do more setup to use loadView.

I'm using the View Swapping code from Hillegass's book Cocoa Programming for MAC OS X which switches ViewControllers with the following code:

  - (void)displayViewController:(ManagingViewController *)vc
                   curBox: (NSBox *)windowBox

  {
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
    NSBeep();
    return;
}
NSView *v = [vc view];

NSSize currentSize = [[windowBox contentView] frame].size;

NSSize newSize = [v frame].size;

float deltaWidth  = newSize.width  - currentSize.width;
float deltaHeight = newSize.height - currentSize.height;

NSRect windowFrame = [w frame];
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;

[windowBox setContentView:nil];
[w setFrame:windowFrame
    display:YES
    animate:YES];

[windowBox setContentView:v];

// Put the view controller in the responder chain

[v setNextResponder:vc];
[vc setNextResponder:windowBox];
 }

and puts the NSView Controller in the responder chain.

Is there some function I can call to setup the view every time I swap NSViewControllers? Can I check that a NSViewController has become the firstResponder?

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

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

发布评论

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

评论(1

庆幸我还是我 2024-10-25 20:06:07

这篇帖子提供了答案。

我添加了以下代码:

- (void)viewWillLoad {

}

- (void)viewDidLoad {

}

- (void)loadView {
[self viewWillLoad];
[super loadView];
[self viewDidLoad];
}

并在 displayViewController 的开头添加了

[vc loadView]

This post provided the answer.

I added the following code:

- (void)viewWillLoad {

}

- (void)viewDidLoad {

}

- (void)loadView {
[self viewWillLoad];
[super loadView];
[self viewDidLoad];
}

and at the beginning of displayViewController I added

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