我试图弄清楚如何在NSViewController中重新加载数据。

我有一个这样的项目,左侧​​栏是NSOutlineView(由我的outlineViewController控制),右侧拆分视图是一个自定义视图:
xcode - 如何在NSViewController中重新加载数据?-LMLPHP


因此,我有了这个“ profile.xib”文件,其中包含“人”对象的一些信息。我已经将profile.xib文件所有者设置为我的视图控制器ProfileViewController,它是NSViewController的子类。

因此,每次用户从侧边栏选择不同的配置文件时,我的outlineviewController都会调用:

if (!_profileViewController)
_profileViewController = [[ProfileViewController alloc] initWithNibName:@"profile" bundle:nil];
[_profileViewController setProfile: item]; //item is an instance of the profile object
NSView *view = [_profileViewController view];
view.frame = _mainContentView.bounds;
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[_mainContentView addSubview:view]; //add profile's view to the right hand side split view


(代码取自apple的sidebardemo)

由于用户可以从侧边栏中选择其他配置文件,因此我需要在ProfileViewController中重新加载数据。但是我不知道哪个方法应该包含我的重载数据代码。如果我将我的“重载数据代码”放在awakefromnib中,它将被调用一次,viewload也将被调用一次。由于内存问题,我不想在选择配置文件时重新分配和重新初始化_profileViewController的所有内容。

我不能在这里使用绑定,因为某些字段显示起来非常复杂。

所以我要如何重新加载数据?

最佳答案

如何将您的“将配置文件信息加载到视图中”代码从-awakeFromNib移到其自己的-reloadData方法中,并在调用-setProfile:时进行调用?您可以通过从表视图中自己调用它,也可以通过重写-setProfile:来进行记录,以记录该概要文件,然后立即调用-reloadData。

关于xcode - 如何在NSViewController中重新加载数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15792457/

10-10 22:25