NSTableView 的列绑定到不同的 NSArrayController
我有 NSTableView 和其中的两列:
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease];
[column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil];
[table addTableColumn:column];
column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease];
[column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil];
[table addTableColumn:column];
如您所见,列绑定到不同的 NSArrayController。第一列显示正确的值,但第二列仅显示“(”符号。但是如果我像这样交换列:
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease];
[column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil];
[table addTableColumn:column];
column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease];
[column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil];
[table addTableColumn:column];
那么我会看到第一列的值(在第一个示例中是第二列),然后在第二列中再次看到“(”。我不明白这种行为。我如何将两个数组控制器绑定到一张表?
i have NSTableView and two columns in it:
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease];
[column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil];
[table addTableColumn:column];
column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease];
[column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil];
[table addTableColumn:column];
as you can see, columns bound to different NSArrayControllers. first column shows correct values, but second just shows "(" symbol. but if i swap columns like this:
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:@"totalGrams"] autorelease];
[column bind:@"value" toObject:valuationArrC withKeyPath:@"arrangedObjects.totalGrams_double" options:nil];
[table addTableColumn:column];
column = [[[NSTableColumn alloc] initWithIdentifier:@"custId"] autorelease];
[column bind:@"value" toObject:arrC2 withKeyPath:@"arrangedObjects.custId" options:nil];
[table addTableColumn:column];
then i see values of first column (which was second in the first example) and again "(" in the second column. i don't understand that behaviour. how can i bound two array controllers to one table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如我发现的,将多个控制器绑定到一个视图是不可能的。可能的解决方案是创建一个“代理”对象,它具有多个属性,然后将该对象与像
prop1.someRealProp 这样的键路径绑定
prop2.someRealPropOfSecondObject
as i found out, binding several controllers to one view is not possible. possible solution is to create a "proxy" object, which has a several properties, and then bind this object with a keypath like
prop1.someRealProp
prop2.someRealPropOfSecondObject