展开从数据源加载数据的 NSOutlineView 的所有项目

发布于 2024-08-28 22:05:43 字数 320 浏览 8 评论 0原文

首先,我是可可开发的新手,所以我想我可能试图以错误的方式执行此操作,但这里是:

我有一个 NSOutlineView ,它从 NSOutlineViewDataSource 加载数据实施。我希望所有项目在加载后展开,但我似乎找不到数据加载完成时触发的事件,因此我可以发送 [outlineView ExpandItem: nil ExpandChildren: YES] 到它。

我研究了 NSOutlineViewDelegate 协议,但无法找到适合此调用的位置。解决这个问题的最佳方法是什么?

First of all I'm new to cocoa development so I suppose I'm probably trying to do this the wrong way, but here goes:

I have a NSOutlineView which loads the data from a NSOutlineViewDataSource implementation. I want all the items to be expanded after they are loaded, but i can't seem to find an event fired when the data has finished loading, so I can send a [outlineView expandItem: nil expandChildren: YES] to it.

I looked into the NSOutlineViewDelegate protocol but I was unable to find a suitable place for this call. What would be the best approach for this problem?

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

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

发布评论

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

评论(4

无可置疑 2024-09-04 22:05:44

通常我喜欢在表单中执行类似的操作 - awakeFromNib 或任何其他启动回调

dispatch_async(dispatch_get_main_queue(), ^{
    [self.outlineView expandItem:root expandChildren:YES];
});

这会将执行块在运行循环中的当前周期结束时排队,因此,它将在所有初始化完成后执行。无需设置任何人为延迟。

Normally I like to do something like this inside form - awakeFromNib or any other startup callbacks

dispatch_async(dispatch_get_main_queue(), ^{
    [self.outlineView expandItem:root expandChildren:YES];
});

This will enqueue the execution block at the end of the current cycle in the runloop, thus, it will be executed after all initialization has taken place. There's no need to set any artificial delay.

百变从容 2024-09-04 22:05:44

我想出的最佳解决方案是编写一个在零延迟后扩展 NSOutlineView 的方法。

- (void)windowDidLoad
{
    [super windowDidLoad];
    [self performSelector:@selector(expandSourceList) withObject:nil afterDelay:0.0];
}

- (IBAction)expandSourceList
{
    [mSourceListView expandItem:nil expandChildren:YES];
}

The best solution I've come up with is to write a method that expands the NSOutlineView after a delay of zero.

- (void)windowDidLoad
{
    [super windowDidLoad];
    [self performSelector:@selector(expandSourceList) withObject:nil afterDelay:0.0];
}

- (IBAction)expandSourceList
{
    [mSourceListView expandItem:nil expandChildren:YES];
}
月牙弯弯 2024-09-04 22:05:44

我找到了答案。看来实现委托方法 -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
会成功的:


-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
    [outlineView expandItem:item];
}

I found the answer. It seems that implementing the delegate method -(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
will do the trick:


-(void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
    [outlineView expandItem:item];
}
猫腻 2024-09-04 22:05:44

这是我通常处理这个问题的方式。我喜欢自己显示我的主窗口而不是让它自动发生。这使我能够在向用户显示窗口之前确保所有界面项目都按照我想要的方式设置。看来你也可以做到这一点。因此,首先我在窗口的界面生成器中取消选中“启动时可见”。然后在我的应用程序的委托类中,我使用这个方法,它是 NSApplication 的删除方法:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

在那里我设置了我的界面项,因为那时我知道一切已加载。然后该方法的最后一行将是:[myWindow makeKeyAndOrderFront:self];。这样,您就可以在用户看到窗口之前知道您的窗口是完美的。所以我会在那里尝试你的方法。

Here's how I normally handle this. I like to show my main window myself rather than letting it happen automatically. This allows me to make sure all of my interface items are setup how I want before I show the user the window. It seems you could do this too. So first I uncheck "Visible at launch" in interface builder for the window. Then in my application's delegate class I use this method which is a deleate method of NSApplication:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

In there I setup my interface items because at that point I know everything is loaded. And then the last line of that method would be: [myWindow makeKeyAndOrderFront:self];. This way you know your window is perfect before your user sees the window. So I would try your method there.

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