Getting button binding to invoke an action

  • I am trying to understand how I can use Cocoa binding in my
    application development.

    As an experiment, I've created a Cocoa application.  In the NIB file
    I have instantiated an NSObjectController, and instance of a custom
    class I want the controller to manipulate.  I have connected the
    class instance to the content outlet of the NSObjectController instance.

    Next, I added an NSButton to the view in main window.  I tried to
    create a binding such that when the button is clicked, an action
    would be called in my controlled class.

    I have tried binding the target for the button to the selection of
    the NSObjectController, and specifying the desired action in the
    custom class as the selector.

    When I run the application and click on the button, the program
    crashes with a EXC_BAD_ACCESS signal the following stack trace:
    #0    0x92bd7478 in +[NSInvocation newInvocationWithMethodSignature:]
    #1    0x92c5f494 in +[NSInvocation invocationWithMethodSignature:]
    #2    0x93c55dc4 in -[NSObject(_NSBinderKeyValueCodingAdditions)
    _invokeSelector:withArguments:onKeyPath:]
    #3    0x93c7e268 in -[NSObjectController
    _invokeSingleSelector:withArguments:onKeyPath:]
    #4    0x93c55d94 in -[NSObject(_NSBinderKeyValueCodingAdditions)
    _invokeSelector:withArguments:onKeyPath:]
    #5    0x93c61a60 in -[NSBinder
    _invokeSelector:withArguments:onKeyPath:ofObject:mode:raisesForNotApplic
    ableKeys:]
    #6    0x93c62024 in -[NSBinder
    invokeSelector:withArguments:forBinding:error:]
    #7    0x93c81a24 in -[NSActionBinder
    _invokeSelector:withArguments:forBinding:]
    #8    0x93c82130 in -[NSActionBinder _executePerformAction]
    #9    0x93c822f4 in -[NSActionBinder
    _performActionWithCommitEditing:didCommit:contextInfo:]
    #10    0x90a451f4 in objc_msgSendv
    #11    0x92bdec94 in -[NSInvocation invoke]
    #12    0x92bdf244 in -[NSInvocation invokeWithTarget:]
    #13    0x93c590e4 in _NSSendCommitEditingSelector
    #14    0x93c7c600 in -[NSController
    _controllerEditor:didCommit:contextInfo:]
    #15    0x90a451f4 in objc_msgSendv
    #16    0x92bdec94 in -[NSInvocation invoke]
    #17    0x92bdf244 in -[NSInvocation invokeWithTarget:]
    #18    0x92bedc04 in __NSFireDelayedPerform
    #19    0x907f1578 in __CFRunLoopDoTimer
    #20    0x907ddef8 in __CFRunLoopRun
    #21    0x907dd4ac in CFRunLoopRunSpecific
    #22    0x9329bb20 in RunCurrentEventLoopInMode
    #23    0x9329b12c in ReceiveNextEventCommon
    #24    0x9329b020 in BlockUntilNextEventMatchingListInMode
    #25    0x937a1ae4 in _DPSNextEvent
    #26    0x937a17a8 in -[NSApplication
    nextEventMatchingMask:untilDate:inMode:dequeue:]
    #27    0x9379dcec in -[NSApplication run]
    #28    0x9388e87c in NSApplicationMain
    #29    0x0000ef34 in main at main.mm:9

    The action for the custom class has the standard signature:  - (void)
    actionName:(id)sender.

    What is needed to get the button binding to successfully invoke the
    desired action?
  • on 9/8/07 9:01 PM, <tron.thomas...> purportedly said:

    > As an experiment, I've created a Cocoa application.  In the NIB file
    > I have instantiated an NSObjectController, and instance of a custom
    > class I want the controller to manipulate.  I have connected the
    > class instance to the content outlet of the NSObjectController instance.
    >
    > Next, I added an NSButton to the view in main window.  I tried to
    > create a binding such that when the button is clicked, an action
    > would be called in my controlled class.
    >
    > I have tried binding the target for the button to the selection of
    > the NSObjectController, and specifying the desired action in the
    > custom class as the selector.
    >
    > When I run the application and click on the button, the program
    > crashes with a EXC_BAD_ACCESS signal the following stack trace:

    The "selection" property of NSObjectController does not return an instance
    of your model class, but a proxy object that won't respond to any
    non-accessor methods. Now, I can't think of why this would cause a bad
    access error, but it wouldn't work anyway. Bind to the controller key
    "content" instead.

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today