Search code examples
objective-ccocoacocoa-bindingsnstablecellview

Binding inside a NSTableCellView


I'm using a NSOutlineView view based and i want to bind a NSSlider and a NSTextfield to a NSDictionary key (@""duration"). The dictionary is a property of my NSTableCellView subclass. I'm facing an error when trying to setup the binding :

The error :

*** 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;

    ...

My NSOutlineView view:

NSTableColumn

NSTableColumn:

Last

NSTextField Binding Setup:

Binding Setup Binding setup 2

The wanted result :

Jimi Hendrix

How to setup the binding to get what i want ?


Solution

  • As Said before, File's Owner.info.duration Make no sense because File's Owner is kind off class outlineview. The dictionary Info is a property off ObjectFileTableCellView.

    I bound programmatically the NSTextfield to info.duration and it work great !