Я смотрел на эту проблему на прошлой неделе. Бесчисленные чашки Джо, кошек, наступающих на мою клавиатуру, и подруги, желающей, чтобы я потом соскочил с ноутбука - я до сих пор не могу понять это. Надеюсь, что я делаю что-то очень глупое (100% -ый шанс), что я смотрю.
У меня есть код, который добавляет десятичную к цифровой клавиатуре. Большая часть кода была взята отсюда (http://brygruver.squarespace.com/blog/2009/10/1/creating-a-custom-number-pad.html?lastPage=true&postSubmitted=true), и я использую его код, но немного изменил его, чтобы добавить только десятичную дробь и изображение десятичной дроби к двум последним полям из моих общих пяти полей.
Вот мой код, который показывает десятичное изображение и добавляет его к входу:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
// We need to access the dot Button declared in the Delegate.
helloAppDelegate *appDelegate = (helloAppDelegate *)[[UIApplication sharedApplication] delegate];
// Only if we are editing within the Number Pad Text Field do we want the dot.
if (textField == txtUserName4) {
// Show the Dot.
appDelegate.dot.hidden = NO;
}
else if (textField == txtUserName5) {
// Show the Dot.
appDelegate.dot.hidden = NO;
}
else {
// Otherwise, Hide the Dot.
appDelegate.dot.hidden = YES;
}
}
- (void)addDecimal:(NSNotification *)notification {
// Apend the Decimal to the TextField.
if (txtUserName4.editing) {
txtUserName4.text = [txtUserName4.text stringByAppendingString:@"."];
}
else if (txtUserName5.editing) {
txtUserName5.text = [txtUserName5.text stringByAppendingString:@"."];
}
вот видео о том, что происходит (http://screencast.com/t/OTNhODRiYjAt). Десятичное число не показывает , если я не выведу сообщение об ошибке , и затем оно будет отображаться правильно для обоих полей.
ТАК, я отключил проверку поля и - шокирующе - десятичное число отображается в последних двух полях (http://screencast.com/t/ZmQyOTc1MT). Так что это должен быть не код, показывающий десятичные дроби, а имеющаяся у меня проверка.
вот подтверждение, которое я имею. Я думаю, что я бросаю мяч с текстовым полем, равным нулю или первым отвечающим?
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == txtUserName)
{
NSString *userNameOne = txtUserName.text;
double numOne = [userNameOne doubleValue];
if(numOne < 30 || numOne > 80)
{
//show alert
//release alert
//if there is alert then clear out the field and make that the FR
[txtUserName becomeFirstResponder];
txtUserName.text = nil;
}
else
{
[txtUserName2 becomeFirstResponder];
}
}
else if (textField == txtUserName2)
{
NSString *userNameThree = txtUserName2.text;
float numTwo = [userNameThree doubleValue];
if (numTwo < 20 || numTwo > 32)
{
//show alert
//release alert
//if there is alert then clear out the field and make that the FR
[txtUserName2 becomeFirstResponder];
txtUserName2.text = nil;
}
else
{
[txtUserName3 becomeFirstResponder];
}
}
else if (textField == txtUserName3)
{
NSString *userNameThree = txtUserName3.text;
float numThree = [userNameThree doubleValue];
if (numThree < 475 || numThree > 650)
{
//show alert
//release alert
//if there is alert then clear out the field and make that the FR
[txtUserName3 becomeFirstResponder];
txtUserName3.text = nil;
}
else
{
[txtUserName4 becomeFirstResponder];
}
}
else if (textField == txtUserName4)
{
NSString *userNameFour = txtUserName4.text;
double numFour = [userNameFour doubleValue];
if (numFour < 0.5 || numFour > 3.00)
{
//show alert
//release alert
//if there is alert then clear out the field and make that the FR
[txtUserName4 becomeFirstResponder];
txtUserName4.text = nil;
}
else
{
[txtUserName5 becomeFirstResponder];
}
}
else if (textField == txtUserName5)
{
NSString *userNameFive = txtUserName5.text;
double numFive = [userNameFive doubleValue];
if (numFive > 0.80)
{
//show alert
//release alert
//if there is alert then clear out the field and make that the FR
[txtUserName5 becomeFirstResponder];
txtUserName5.text = nil;
}
else
{
[txtUserName5 resignFirstResponder];
}
}
}
Я действительно в замешательстве, но, по крайней мере, понял, что с моей проверкой что-то путается ...
EDIT:
Я обнаружил, что если я закомментирую else
, который делает следующее поле первым респондентом, тогда все работает как надо.
С учетом сказанного, действительно ли удаление else
повредило что-либо в моей проверке? Вся эта проверка была сделана с целью использовать кнопки «Готово» и «Далее» назад, когда я использовал основную клавиатуру. Теперь я вижу, что весь мой код проверки немного не хватает:)