views:

27

answers:

1

I want to have a button where if I click it, then some text is displayed that says "you clicked the button." I know how to do this using IBOutlet and IBAction. Can it be done with bindings? If so, then how?

+1  A: 

I don't think so. You can't bind a momentary button to a property and expect that to work correctly. What would you bind on the button side? After pressing and releasing a momentary button, the button's state is unchanged, so there's nothing to bind do.

Kevin Ballard
If I wanted to do something similar then, and not use a button, then what could I use?
Phenom
Phenom: The problem isn't the button. The problem is you're trying to bind a persistent state (pressed appearance) to a momentary action. It doesn't matter what view has the state, or what control is sending the action. You can only bind a property (persistent) to a property (persistent); binding it to an action (momentary) just doesn't make sense.
Peter Hosey
What if I used a checkbox? That might have a property of checked or not checked.
Phenom
Binding to a checkbox works, because the checkbox has a persistent state. Similarly, you could bind to a non-momentary button (e.g. one which stays depressed after you press it).
Kevin Ballard
That said, binding *to* a view is wrong. The object you bind to is the one that holds the value, and it is wrong to use views as value-holders. The main object that holds the value should be a controller, and all views should get the value from and pass new values to the controller. When you bind all your views to a property the controller, they all get notified automatically when one them sets that property to a new value.
Peter Hosey