0

我正在使用基于 NSOutlineView 的视图,并且我想将 NSSlider 和 NSTextfield 绑定到 NSDictionary 键(@""duration")。字典是我的 NSTableCellView 子类的属性。尝试设置时遇到错误绑定:

错误 :

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSApplication 0x100506400> addObserver:<NSTextValueBinder 0x102609a90> forKeyPath:@"info.duration" options:0 context:0x10260c820] was sent to an object that is not KVC-compliant for the "info" property.'

。H:

#import <Cocoa/Cocoa.h>

@interface ObjectFileTableCellView : NSTableCellView {
    NSTextField *_textFieldFilePath;
    NSTextField *_textFieldDesription;
    NSButton *_checkBox;
    NSDictionary* _info;

    NSSlider*  _slider;
    NSTextField* _labelStartTime;
}


@property(retain) IBOutlet NSTextField *textFieldFilePath;
@property(retain) IBOutlet NSTextField *textFieldDescription;
@property(retain) IBOutlet NSTextField *labelStartTime;
@property(retain) IBOutlet NSSlider *slider;
@property(retain) IBOutlet NSButton *checkBox;

@property(retain) NSDictionary* info;

@end

.m:

- (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{
    if ([[tableColumn identifier] isEqualToString:@"Files"]) {

        if ([item isKindOfClass:[OMN_Object class]])
        {

//DONE - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item{ if ([[tableColumn identifier] isEqualToString:@"Files"]) {

    if ([item isKindOfClass:[OMN_Object class]])
    {
        OMN_Object *o = item;

        ObjectFileTableCellView *v = [outlineView makeViewWithIdentifier:@"FileCell" owner:self]; // File'S owner


                hide = NO;
                NSString* d = [o.fileInfoDetails valueForKey:@"duration"];
                [v.slider setMinValue:0];
                [v.slider setMaxValue:[d doubleValue]];

                NSString *val = [NSString stringWithFormat:@"%f", v.slider.doubleValue];
                [v.labelStartTime setStringValue:val];
                [o.fileInfoDetails setValue:val forKey:@"startTime"];
                v.info = o.fileInfoDetails;

    ...

我的 NSOutlineView 视图:

NSTableColumn

NSTable 列:

最后的

NSTextField 绑定设置:

绑定设置 装订设置 2

想要的结果:

吉米亨德里克斯

如何设置绑定以获得我想要的?

4

2 回答 2

0

如前所述,File's Owner.info.duration 毫无意义,因为 File's Owner 有点类似于类大纲视图。字典信息是 ObjectFileTableCellView 的一个属性。

我以编程方式将 NSTextfield 绑定到 info.duration 并且效果很好!

于 2013-08-26T21:22:56.580 回答
0

您正在尝试绑定info.duration到单元格本身,而不是文本字段,假设“文件的所有者”确实是您的ObjectFileTableCellView.

配置绑定labelStartTime时用作控制器键。

仔细检查滑块的绑定配置;你可能犯了类似的错误。

于 2013-08-23T14:07:07.513 回答