在NSTableCellView中绑定

时间:2013-08-23 12:47:18

标签: objective-c cocoa cocoa-bindings nstablecellview

我正在使用基于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

NSTableColumn:

Last

NSTextField绑定设置:

Binding Setup Binding setup 2

想要的结果:

Jimi Hendrix

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

2 个答案:

答案 0 :(得分:0)

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

配置绑定时使用labelStartTime作为控制器密钥。

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

答案 1 :(得分:0)

如前所述,文件的Owner.info.duration毫无意义,因为文件的所有者是一个非常类的概述。字典Info是ObjectFileTableCellView的一个属性。

我以编程方式将NSTextfield绑定到info.duration,它工作得很好!