0

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?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
neuromancer
  • 53,769
  • 78
  • 166
  • 223

1 Answers1

1

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.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • If I wanted to do something similar then, and not use a button, then what could I use? – neuromancer Jul 07 '10 at 22:43
  • 1
    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 Jul 07 '10 at 23:15
  • What if I used a checkbox? That might have a property of checked or not checked. – neuromancer Jul 07 '10 at 23:34
  • 1
    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). – Lily Ballard Jul 08 '10 at 01:28
  • 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 Jul 08 '10 at 05:41