Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Qaanol

macrumors 6502a
Original poster
Jun 21, 2010
571
11
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.
 
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.

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.
 
Last edited:
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.
 
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.

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.
 
Look in the Bindings pane of the Interface Builder Inspector: there will be "Placeholder" fields in which you can specify the default values.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.