2012-09-09 148 views
1

標籤我想爲iphone做一個計算器應用程序 所以現在我完成了所有操作,並且我想讓用戶在文本字段中輸入他的第一個數字然後如果他點擊'+'按鈕我想要測試字段開關或標籤到另一個文本字段如何從文本字段1到文本字段2通過按下按鈕

那麼我該怎麼做呢? 這裏是頭

#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{ 
    [email protected]"+"; 


} 
-(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]; 
    [email protected]""; 
    [email protected]""; 
    [email protected]""; 
    a=0; 
    b=0; 
    c=0; 
    [email protected]""; 
    op=' '; 

} 

回答

2

如果我正確理解你的代碼,用戶輸入的第一-sum:sender被調用後。您可以在第二個UITextField上撥打becomeFirstResponder

-(IBAction)sum:(id)sender{ 
    [email protected]"+"; 
    [num2 becomeFirstResponder]; 
} 
相關問題