我正在尝试为iphone制作计算器应用程序 所以现在我完成了所有操作,如果用户在文本字段中输入了他的第一个数字,然后如果他点击了“+”按钮我希望测试字段开关或制表符到另一个文本字段
所以我该怎么办? 这是标题
#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文件
#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=' ';
}
答案 0 :(得分:2)
如果我正确理解您的代码,在用户输入后,第一个-sum:sender
被调用。您只需在第二个UITextField上调用becomeFirstResponder
。
-(IBAction)sum:(id)sender{
operation.text=@"+";
[num2 becomeFirstResponder];
}