1

我正在尝试为 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=' ';

}
4

1 回答 1

2

如果我正确理解了您的代码,则在用户输入第一个代码后-sum:sender会被调用。您可以只调用becomeFirstResponder第二个 UITextField。

-(IBAction)sum:(id)sender{
    operation.text=@"+";
    [num2 becomeFirstResponder];
}
于 2012-09-09T18:21:15.603 回答