I am trying to make a calculator app for iphone
so now i finished all operations and i want to make if the user typed in the text field his first number and then if he tapped the ‘+’ button i want the test field switch or tab to the another text field
so how can i do it ?
here is the header
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
int a,b,c;
char op;
UILabel*operation,*result;
UITextField *num1,*num2;
}
@property (nonatomic)int a , b ,c;
@property (nonatomic)char po;
@property (nonatomic ,retain)IBOutlet UILabel*operation,*result;
@property (nonatomic ,retain)IBOutlet UITextField *num1,*num2;;
-(IBAction)sum:(id)sender;
-(IBAction)Calculate:(id)sender;
-(IBAction)Clear:(id)sender;
-(IBAction)hideKeyboard:(id)sender;
@end
.m file
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize operation,result,num1,num2,a,b,c,po;
-(IBAction)sum:(id)sender{
operation.text=@"+";
}
-(IBAction)hideKeyboard:(id)sender{
[num1 resignFirstResponder];
[num2 resignFirstResponder];
}
-(IBAction)Calculate:(id)sender{
//sum
a =num1.text.integerValue;
b= num2.text.integerValue;
c=num1.text.integerValue+num2.text.integerValue;
printf("%i >> %i",b,num2.text.integerValue);
[num1 resignFirstResponder];
[num2 resignFirstResponder];
result.text =[NSString stringWithFormat:@"%i + %i = %i",a,b,c];
}
-(IBAction)Clear:(id)sender{
[num1 resignFirstResponder];
[num2 resignFirstResponder];
num1.text=@"";
num2.text=@"";
operation.text=@"";
a=0;
b=0;
c=0;
result.text=@"";
op=' ';
}
If I understand your code correctly, after the user inputs the first
-sum:sendergets called. You can just callbecomeFirstResponderon the second UITextField.