我想創建一個簡單的計算器應用程序,它具有稍微不同的界面設計。如下圖所示,我有三個來自用戶的輸入:第一個數字,操作員和第二個數字。我的問題是,一旦用戶滿足這三個文本字段,然後等號(resultBtn)改變顏色。我想知道如何知道所有這些文本框是否已滿。順便說一句,我剛剛將Xcode從5.1更新到6.0.1,然後一旦我點擊文本框,鍵盤就不會顯示出來。如何知道textFields是全滿的
- (IBAction)resultBtn:(id)sender {
double temp;
if([operatorTF.text isEqual:@"+"])
{
temp=[calculate arithmetic:[firstNumberTF.text doubleValue] enterCharacter:Plus enterSecond:[secondNumberTF.text doubleValue]];
}
else if([operatorTF.text isEqual:@"-"])
{
temp=[calculate arithmetic:[firstNumberTF.text doubleValue] enterCharacter:Minus enterSecond:[secondNumberTF.text doubleValue]];
}
else if([operatorTF.text isEqual:@"/"])
{
temp= [calculate arithmetic:[firstNumberTF.text doubleValue] enterCharacter:Divide enterSecond:[secondNumberTF.text doubleValue]];
}
else if([operatorTF.text isEqual:@"^"])
{
temp= [calculate arithmetic:[firstNumberTF.text doubleValue] enterCharacter:Power enterSecond:[secondNumberTF.text doubleValue]];
}
else {
temp= [calculate arithmetic:[firstNumberTF.text doubleValue] enterCharacter:Multiply enterSecond:[secondNumberTF.text doubleValue]];
}
resultTF.hidden= NO;
resultTF.text=[NSString stringWithFormat:@"%1.2f",temp];
}
- (IBAction)clearBtn:(id)sender {
firstNumberTF.text = nil;
resultTF.text = nil;
secondNumberTF.text = nil;
operatorTF.text=nil;
resultTF.hidden= YES;
// [resultBtnOutlet setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
}
- (BOOL)textFieldShouldReturn: (UITextField *)textField {
if(textField.tag == 0)
{
firstNumberTF.text = textField.text;
}
else if(textField.tag == 1)
{
operatorTF.text = textField.text;
}
else if(textField.tag == 2)
{
secondNumberTF.text = textField.text;
}
else
{
resultTF.text = textField.text;
}
[textField resignFirstResponder];
return YES;
}
你是什麼意思「全」?填寫? – Raptor 2014-09-19 02:35:39
我的意思是它由用戶填滿,換句話說它不是空的 – casillas 2014-09-19 02:36:03
如果檢查文本字段不是空的,你可以嘗試textfield.text.length> 0 – 2014-09-19 02:37:41