How can I set an int value in some code to be equal to a value in a text entry box?
I'm try开发者_高级运维ing to get a value from an object in my mac application.
NSControl
, of which NSTextField
is a subclass, has a method intValue
, which gets you what you want. Set up an outlet in your controller and use Interface Builder to hook it up to the text field you care about. After that, your controller can just access it like:
int myInt = [myTextField intValue];
The outlet declaration would look something like:
IBOutlet NSTextField *myTextField;
Along with your controller's other instance variables.
精彩评论