Get int from textField

I am new to cocoa. I am creating a project where I have one text screen and one button. I make a function for the button, where I run my other function, and everything is fine. But I need to take the value of number from textField as a parameter for my function ... for example:

@implementation AppController

- (IBAction)StartReconstruction:(id)sender {
    int RecLine = //here i need something like textField1.GetIntValue();
    drawGL(RecLine);
}
@end

In IB, I only create a text box with numeric forms. But I do not know what to call it from the code :(

thanks for the help

+5
source share
6 answers

Have you connected a text box between your code and IB? You will need to define ivar and the property in the @interface declaration, for example:

@interface BlahBlah {
    UITextField *textField1;
}
@property (nonatomic, retain) IBOutlet UITextField *textField1;


...
@end

, ivar IB ( google, , ),

[textField1.text intValue];

(, ).

+3

. NSTextField NSControl, intValue, ...

-(IBAction)buttonClicked:(id)sender
{
    int intVal = [textField intValue];
    NSLog (@"Int value is %i", intVal);
}
+2

IBOutlet , Interface Builder? , . :

@interface AppController
{
    NSTextField *myTextField;
}

@property (nonatomic, retain) IBOutlet NSTextField *myTextField;

:

@synthesize myTextField;

IB "File Owner". , "myTextField".

int, :

[myTextField.stringValue intValue]
+1

:


int RecLine = [textField1.text intValue];

, textField1 -, .

0

, SDK OS X 10.5 . :

Project > Edit Project Settings > Build > Base SDK 

enter image description here

-1

NSString * x = self.textfield1.text;

Int recLine = [x intValue];

-1

All Articles