I'm new to cocoa. I create project where I have one textField and one button. I make function for button, where I start my other function and it's ok. But I need to take number value from textField as parameter for my function...like this:
@implementation AppController
- (IBAction)StartReconstruction:(id)sender {
int RecLine = //here i need something like textField1.GetIntValue();
drawGL(RecLine);
}
@end
In IB I only create number formated text field. But I don't know how to call it from code :(
thanks for help
Have you connected the textfield between your code and IB? You will need to define the ivar and property in your @interface declaration, like this:
@interface BlahBlah {
UITextField *textField1;
}
@property (nonatomic, retain) IBOutlet UITextField *textField1;
...
@end
After you have declared your ivar and connected it to your text box in IB (search google to see how), you can simply call
[textField1.text intValue];
to get the integer value of the string in the textbox (mind you, this is quick and dirty and does not validate the input).
you don't have to get text value first. NSTextField inherits from NSControl which has intValue method, so...
-(IBAction)buttonClicked:(id)sender
{
int intVal = [textField intValue];
NSLog (@"Int value is %i", intVal);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With