可可结合NSTableView中的NSTableView [英] Cocoa binding NSTableView within NSTableView

查看:57
本文介绍了可可结合NSTableView中的NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NSTableView内显示NSTableView。这适用于类似iTunes的专辑/曲目视图。因此,这里列出了10张专辑,每张专辑都有一些曲目。我想在外部表视图中显示专辑,在内部表中显示每个专辑的曲目。

I'm trying to display a NSTableView inside a NSTableView. This is for an iTunes-like albums/tracks view. So there's a list of 10 albums, each album has some tracks. I want to display the albums in the outer table view and the tracks for each album in the inner.

第一个NSTableView绑定到NSArrayController。数组中的每个对象都有其自己的轨迹 NSArrayController,但我不知道如何告诉轨迹 NSTableView其内容来自相册 NSTableView的属性。

The first NSTableView is bound to an NSArrayController. Each object in the array has its own "tracks" NSArrayController, but I can't figure out how to tell the 'tracks' NSTableView that its content comes from a property of the 'album' NSTableView.

推荐答案

如果我理解正确,则嵌套数组控制器的源内容来自所有者表单元格的objectValue。因此,您不能将数组控制器的内容源设置为表格单元的objectValue。我在做类似的事情,我想根据对象值过滤数组内容。

If I understand you right, the source content of the nested array controller comes from objectValue of the owner table cell. So you can't put the array controller content source to be the objectValue of the table cell. I'm doing similar in that I want to filter the array content based on the object value

我正在做的似乎有效的工作是嵌套表单元格视图的单独nib文件,以及它自己的nstablecellview子类。将阵列控制器包括在笔尖中,并在单元格视图子类中为其创建出口。

What I'm doing, which seems to be working, is to make a seperate nib file for your nested table cell view, with it's own nstablecellview subclass. Include the array controller in the nib and create an outlet to it in your cell view subclass.

在表视图控制器的viewDidLoad方法中向表视图注册:

Register it with the table view in the viewDidLoad method of the tables view controller:

NSNib *cellView = [[NSNib alloc] initWithNibNamed:@"MyTableCellView" bundle:nil];
[myTableView registerNib:cellView forIdentifier:@"myTableCellView"];

然后,在单元格视图子类的awakeFromNib方法中,手动创建需要对象值的绑定:

Then, in the awakeFromNib method of your cell view subclass, manually make your bindings that require the object value:

[self.arrayController bind:@"contentSet"
                  toObject:self
               withKeyPath:@"objectValue.tracks"
                   options:nil];

Voila。

请注意,使用时这种技术,nib文件的文件所有者不是您的nstablecellview子类,而是表视图的视图控制器。

Note that when using this technique, the files Owner of the nib file is not your nstablecellview subclass, it is the view controller of the table view.

这篇关于可可结合NSTableView中的NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆