【发布时间】:2011-04-25 10:31:49
【问题描述】:
我的应用程序有 2 个窗口,它们都显示由控制器管理的 NSScrollView 对象。基本上第一个有数据,第二个有适当的数据聚合。 两者都依赖于 NSArrayController 类的实现。
我正确设计了两个窗口(至少我相信如此),但我不断收到此错误:
[<MyDocument 0x1020257c0> valueForUndefinedKey:]:
this class is not key value coding-compliant for the key <MY_ARRAY>.
我设法解决这个问题的唯一方法是立即实例化(我的意思是当第一个窗口准备好时)第二个数组并以这种方式填充一些值:
NSMutableArray *newAggregates = [NSMutableArray array];
[newAggregates addObject:
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithString:@"category"], @"category",
[NSString stringWithString:@"subcategory"], @"subcategory",
[NSNumber numberWithFloat:0.0], @"amount_1",
[NSNumber numberWithFloat:0.0], @"amount_2",
[NSNumber numberWithFloat:0.0], @"amount_3",
[NSNumber numberWithFloat:0.0], @"amount_4",
[NSNumber numberWithFloat:0.0], @"amount_5",
[NSNumber numberWithFloat:0.0], @"amount_6",
[NSNumber numberWithFloat:0.0], @"amount_7",
[NSNumber numberWithFloat:0.0], @"amount_8",
[NSNumber numberWithFloat:0.0], @"amount_9",
[NSNumber numberWithFloat:0.0], @"amount_10",
[NSNumber numberWithFloat:0.0], @"amount_11",
[NSNumber numberWithFloat:0.0], @"amount_12",
[NSNumber numberWithFloat:0.0], @"total",
nil]];
[self setAggregates:newAggregates];
这行得通,但这不是我想要的,我希望第二个数组仅当且仅当用户按下某个按钮时才可选地执行。
有没有办法做到这一点,或者应用程序中存在的任何数组控制器都必须在开始时实例化?我绝对肯定有办法避免这种情况......
【问题讨论】:
标签: objective-c xcode nsarraycontroller