我一直在嘗試實現將觸發哪個UITextField的檢查。 以下是我對前兩個文本字段的研究結果。 這給了我兩個錯誤,說「發送者未申報」... 我在哪裏做錯了? 在此先感謝 屬性和綜合都OK! val是按鈕的一個計算器標籤值(例如0,1,2,3,4,5,6,7,8,9)檢查哪個UITextField將被觸發(textFieldShouldBeginEditing)
//.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;
}
請重新格式化您的代碼 - http://stackoverflow.com/editing-help – hoha 2011-03-15 22:02:50