Bindings question: default value

Discussion in 'Mac Programming' started by Qaanol, Nov 17, 2013.

  1. Qaanol macrumors 6502a

    Jun 21, 2010
    This is a super basic question, but I am at a loss. I want the default values I enter in Interface Builder to show up when I run my program.

    I have text fields of the “with Number Formatter” variety, each with its Value bound to an NSNumber property of a custom object. I have written no code yet, just set up the interface.

    The project builds and runs, but the text fields show as empty. If I disconnect the bindings, they show the default values I entered in IB. So…how do I tell Xcode, “Hey, see these default values in IB? Yeah, use those to populate the NSNumber properties, not the other way around.”

    I’m on 10.9 running Xcode 5.0.2.
  2. devilofspades, Nov 18, 2013
    Last edited: Nov 18, 2013

    devilofspades macrumors member

    Jul 20, 2011
    when you say "bindings" do mean "outlets"? i'm not quite sure what you mean when you say "...value bound to an NSNumber", but if you mean you have an outlet created, then that outlet/property has to be of a type "NSTextField". inside your code you can then later set its value from an NSNumber, and i think that's where your problems.
  3. Qaanol thread starter macrumors 6502a

    Jun 21, 2010
    I mean Cocoa Bindings.

    The binding works. If I enter text in the text fields while the program is running, the NSNumber properties get updated and I can do math with them and display their values and so forth.

    The problem is when the binding is realized at run-time, the value from each NSNumber appears to get propagated to the text field through the binding, when I want the reverse to happen: the value from the text field needs to get propagated to the NSNumber through the binding.
  4. ArtOfWarfare macrumors G3


    Nov 26, 2007
    He means Bindings when he refers to Bindings. It's an OS X only part of Interface Builder... I've used them in some projects but I can't decide if I actually like them or not. On the one hand, when they work, it does away with a lot of glue code. On the other hand, when they don't work, they're one of the biggest PITAs to debug in all of OS X development.
  5. Sydde macrumors 68020


    Aug 17, 2009
    Look in the Bindings pane of the Interface Builder Inspector: there will be "Placeholder" fields in which you can specify the default values.

Share This Page