Bind NSOutlineView & NSTextView to NSTreeController?

Discussion in 'Mac Programming' started by ArtOfWarfare, Dec 8, 2012.

  1. ArtOfWarfare macrumors G3


    Nov 26, 2007
    Hi, I'm trying to do something similar to this:

    Except I have an NSOutlineView instead of an NSTableView.

    The part I get stuck at is binding the NSTextField to my NSTreeController's When I try running, I get this error:

    [<NSOutlineView 0x10107d5d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.
    The thing that seems really odd to me is that it says NSOutlineView is the class it's trying to check at, rather than NSTreeController which seems like it would make a lot more sense... it is set to be bound to Tree Controller.

    If I just uncheck this single binding, my whole app runs fine, so I'm pretty sure this is the cause. If I bind the column to, that works fine. So why not for the text field?

    I'm including a zipped file with my whole project so everyone can look at it and hopefully someone can tell me what I'm doing wrong. I haven't gotten far in the project so there's not much to look at. I think the only file of true interest is ShapeyrDocument.xib, although ShapeyrDocument.xcdatamodeId or ShapeyrOutlineViewController.m might be worth looking in...

    Here's my full stack:

    	0   CoreFoundation                      0x00007fff8b4f20a6 __exceptionPreprocess + 198
    	1   libobjc.A.dylib                     0x00007fff8fd993f0 objc_exception_throw + 43
    	2   CoreFoundation                      0x00007fff8b586229 -[NSException raise] + 9
    	3   Foundation                          0x00007fff8bcea1ec -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 238
    	4   Foundation                          0x00007fff8bc31f59 -[NSObject(NSKeyValueCoding) valueForKey:] + 400
    	5   Foundation                          0x00007fff8bc52808 -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 341
    	6   AppKit                              0x00007fff8911c06c -[NSTreeController _singleValueForKeyPath:] + 162
    	7   Foundation                          0x00007fff8bc527cf -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 284
    	8   AppKit                              0x00007fff89113184 -[NSBinder valueForBinding:resolveMarkersToPlaceholders:] + 163
    	9   AppKit                              0x00007fff89115ad7 -[NSValueBinder _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:] + 667
    	10  AppKit                              0x00007fff8911572c -[NSValueBinder _observeValueForKeyPath:ofObject:context:] + 192
    	11  AppKit                              0x00007fff8911a18b -[NSTextValueBinder _observeValueForKeyPath:ofObject:context:] + 43
    	12  AppKit                              0x00007fff8910a779 -[NSObject(NSKeyValueBindingCreation) bind:toObject:withKeyPath:options:] + 641
    	13  AppKit                              0x00007fff88f9317a -[NSIBObjectData nibInstantiateWithOwner:topLevelObjects:] + 1012
    	14  AppKit                              0x00007fff88f721fd loadNib + 317
    	15  AppKit                              0x00007fff88f71729 +[NSBundle(NSNibLoading) _loadNibFile:nameTable:withZone:ownerBundle:] + 219
    	16  AppKit                              0x00007fff890c468c +[NSBundle(NSNibLoading) loadNibFile:externalNameTable:withZone:] + 140
    	17  AppKit                              0x00007fff890f76bb -[NSWindowController loadWindow] + 199
    	18  AppKit                              0x00007fff890f7395 -[NSWindowController window] + 77
    	19  AppKit                              0x00007fff89703721 -[NSDocument(NSPersistentUISupport) restoreDocumentWindowWithIdentifier:state:completionHandler:] + 179
    	20  AppKit                              0x00007fff8930edce -[NSDocumentControllerPersistentRestoration loadedDocument:forAutoID:] + 179
    	21  AppKit                              0x00007fff89314775 __block_global_22 + 254
    	22  AppKit                              0x00007fff893143a3 __block_global_19 + 265
    	23  AppKit                              0x00007fff8931428a __block_global_18 + 688
    	24  AppKit                              0x00007fff89311e2a -[NSDocumentController _openDocumentWithContentsOfURL:usingProcedure:] + 593
    	25  AppKit                              0x00007fff89313fcf __block_global_17 + 251
    	26  libdispatch.dylib                   0x00007fff8c1f6f01 _dispatch_call_block_and_release + 15
    	27  libdispatch.dylib                   0x00007fff8c1f30b6 _dispatch_client_callout + 8
    	28  libdispatch.dylib                   0x00007fff8c1f80c8 _dispatch_main_queue_callback_4CF + 275
    	29  CoreFoundation                      0x00007fff8b4940fe __CFRunLoopRun + 1614
    	30  CoreFoundation                      0x00007fff8b4936b2 CFRunLoopRunSpecific + 290
    	31  HIToolbox                           0x00007fff873450a4 RunCurrentEventLoopInMode + 209
    	32  HIToolbox                           0x00007fff87344e42 ReceiveNextEventCommon + 356
    	33  HIToolbox                           0x00007fff87344cd3 BlockUntilNextEventMatchingListInMode + 62
    	34  AppKit                              0x00007fff88fd2613 _DPSNextEvent + 685
    	35  AppKit                              0x00007fff88fd1ed2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
    	36  AppKit                              0x00007fff88fc9283 -[NSApplication run] + 517
    	37  AppKit                              0x00007fff88f6dcb6 NSApplicationMain + 869
    	38  Shapeyr                             0x0000000100001182 main + 34
    	39  libdyld.dylib                       0x00007fff8808a7e1 start + 0

    Attached Files:

  2. jeanlain macrumors 65816

    Mar 14, 2009
    I found the error. You connected your tree controllers' content outlet to the outline view. That doesn't make sense since the content of your tree controller should be a collection of objects, not a view. So when the text field asks for the controller's selection, a message is sent to the outline view.

    Remove the connection (not the binding between the view and the controller) and it will work fine. You controller is already bound to the managed object context so you don't need to connect its content outlet.
  3. ArtOfWarfare thread starter macrumors G3


    Nov 26, 2007
    Thank you so much!

    How did you manage to find that? I'm wondering what questions you asked that I should have but didn't while trying to resolve this. I got as far as "Why the heck is it an NSOutlineView that's checking for the key?" - but I kept checking and double checking my Tree Controller's class and my Outline View's class and all of their bindings, it never occured to me that Outlets might trump Bindings in some cases, given it seems like in the docs they mostly say "This method does nothing if bindings are set..."
  4. jeanlain macrumors 65816

    Mar 14, 2009
    Since somehow a message was sent to the outline view (instead of the controller's selection) and bindings appeared correct, I looked at all the connections from/to the tree controller and saw the culprit.

Share This Page