I’m just picking up the basics of Cocoa and Interface Builder — using IB version 3.2.6. I’m looking to learn how to use MacRuby for native OS X apps.
I have an NSTextField that I would like to only accept integer values. I used NSNumberFormatter but it doesn’t seem to have an option to only accept integers.
How would you do this? Can it be done in Interface Builder?
A naive but effective approach would be to subclass
NSTextFieldand (this is the naive part) ovverridetextDidChangeto force the digited value to a number:In other words, create a new ruby file in your Classes folder add this code to It and change the field class inside IB (your xib > filed you want to change > inspector > Class dropdown)
Hope this helps.