Hi Michael,

I too have difficulties with IB and bindings - mainly because they are hard to debug - well I find them so (and not just in MacRuby).

When in doubt I blame an IB setting.

I quickly threw together something similar to what you have (except with sliders) , and pretty quickly came to the conclusion that it was not working ;-) - as soon as I embedded my working object into a matrix the KVO stopped working.

 I could get it working quickly sans matrix.

For morale and momentum I would suggest you get things working without the matrix first.

Using MacRuby attr_accessor (at least in my experience) will give you all the kvo magic but if you have a manual changing of the observed value you have to use the given (implicit) setter.

for example:
attr_accessor :billy # will create setter and getter for billy with all the appropritate KVO methods

def updateMyValue(sender) #called from a button perhaps
setBilly(4)
end

#or setValue:4 forKey:billy

#@billy = 4 will not work, because it bypasses the accessor methods


So you don't need to override the accessors unless you are doing some additional work.

If you do override the accessors then you will have to put the whole willChangeValueForKey, and didChangeValueForKey  calls in your overwritten method. 
In your code below you do override the accessor, and therefore lose the KVO.

If you are getting stuck on the simplest of binding I can send you a small project adapted from Hillegass which has an example of KVC.

Re matrix difficulties, a more experienced Cocoa person than me must proffer an explanation ;-).

Hope that helps,
cheers,
John

On Nov 22, 2008, at 1:01 AM, Michael Winterstein wrote:

I'm having difficulty working with bindings and I'm not sure if it's a MacRuby thing or my poor understanding of how they work.

I've tried binding to two types of things - an NSMatrix of radio buttons (binding to "selectedTag") and a Checkbox value.  

Using just an attr_accessor - the variable changes when the user changes them, but changing the variable doesn't update in the UI.
 
So I added an explicit setter method and to change the variable, I use self.setVideoSource(VID_USE_S2) to modify it.

This works to change it on-screen, but now UI changes aren't getting through to the variables properly.  The NSMatrix variable isn't changing, and the other variables are changing but are no longer Boolean.  (If I do a "p x" I get  either #<NSCFBoolean:0xa07f13f8> or #<NSCFBoolean:0xa07f1400>.

I tried replacing 'attr_accessor' with 'attr_reader', and adding an explicit getter. That results in the following when I run (even if I add a 'return nil' to my setter method):

[4169:10b] KVO autonotifying only supports -set<Key>: methods that return void. Autonotifying will not be done for invocations of -[MainWinController setVideoSource:].

I haven't yet tried manual notification because I'm not likely to use bindings for this case if that much work is required.  Is this the expected way to go, or am I missing something here?



Here's a bit of the code (these are set as keys in IB).  When used elsewhere, I just have them as the instance variable :

attr_accessor :audioIncludeS1 # whether to include audio
attr_accessor :audioIncludeS2 # for a particular channel
attr_accessor   :videoSource # which source to use (if any) for video
def setAudioIncludeS1(value)
    @audioIncludeS1 = value
end

def setAudioIncludeS2(value)
    @audioIncludeS2 = value
end

    
def setVideoSource(value)
    case value
        when VID_USE_S1
            @videoSource = VID_USE_S1
        when VID_USE_S2
            @videoSource = VID_USE_S2
        when VID_USE_NONE
            @videoSource = VID_USE_NONE
        else
            @videoSource = VID_USE_NONE
    end
end

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel