Search code examples
cocoacocoa-bindings

Why would you bind the value of a NSProgressIndicator?


What's the point of binding the value of a NSProgressIndicator to your controller? It never seems to ask the controller for the value, except on startup. The only way to move the NSProgressIndicator seems to be by sending it #increaseBy:, which bypasses my binding. So, why would I bind?!


Solution

  • If your UI's bound value not updating, that means you either bungled the binding or your controller code is not modifying the bound value in a key-value-observing–compliant way. The most common problem is doing fooIvar = val rather than [self setFooIvar:val] or self.fooIvar = val.

    Apple's answer to your problem:

    [What to do if] Changing the value of a model property programmatically is not reflected in the user interface

    If changes made to a model value programmatically are not being reflected in the user interface, this typically indicates that the model object is not key-value-observing compliant for the property, or that you are modifying the value in a manner that is bypassing key-value observing. You should ensure that:

    • The model class has automatic key-value observing enabled or implements manual key-value observing for the property.
    • That you are changing the value using an accessor method, or using a key-value-coding compliant method. Changing the value of an instance variable directly does not provide key-value observing change notifications.
    • If your model property is a collection, that you're modifying the content in a key-value-observing compliant manner. See “My collection controller isn’t displaying the current data” for more information.

    For that answer and answers other common problems, see "Troubleshooting Cocoa Bindings."

    You should also look at the examples provided by mmalc. They are a valuable resource.