我一直在尝试实现将触发 UITextField 的检查。以下是我仅针对前两个文本字段的发现结果。这给了我两个错误,上面写着“未声明发件人”......我在哪里做错了?提前感谢 属性和合成都OK!val 是计算器按钮的标记值。(例如 0,1,2,3,4,5,6,7,8,9)
//.h file
IBOutlet UITextField *textFieldLoanAmountDisplay;
IBOutlet UITextField *textFieldInitDepositDisplay;
// .m file
const NSString *textField1Code= @"1";
const NSString *textField2Code= @"2";
-(BOOL)textField1ShouldBeginEditing:(UITextField *)textFieldLoanAmountDisplay {
if (textFieldLoanAmountDisplay == textField1Code)
{
UIButton *buttonPressed = (UIButton *)sender;
int val = buttonPressed.tag;
if ( [textFieldLoanAmountDisplay.text compare:@"0"] == 0 ) {
textFieldLoanAmountDisplay.text = [NSString stringWithFormat:@"%d", val ];
} else {
textFieldLoanAmountDisplay.text = [NSString stringWithFormat:@"%@%d", textFieldLoanAmountDisplay.text, val ];
}
}
return NO;
}
-(BOOL)textField2ShouldBeginEditing:(UITextField *)textFieldInitDepositDisplay {
if (textFieldInitDepositDisplay == textField2Code)
{
UIButton *buttonPressed = (UIButton *)sender;
int val = buttonPressed.tag;
if ( [textFieldInitDepositDisplay.text compare:@"0"] == 0 ) {
textFieldInitDepositDisplay.text = [NSString stringWithFormat:@"%d", val ];
} else {
textFieldInitDepositDisplay.text = [NSString stringWithFormat:@"%@%d", textFieldInitDepositDisplay.text, val ];
}
}
return NO;
}