Iphone 在我的数字键盘上加上这个小数点,我遗漏了什么?
过去一周我一直在关注这个问题。无数杯咖啡,猫踩在我的键盘上,还有女朋友希望我以后离开笔记本电脑——我仍然无法理解这一点。希望我在做一些非常愚蠢的事情,100%的几率我看过头了 我有一些代码在数字键盘上加了一个小数。大部分代码都是从这里获取的,我正在使用他的代码,但对其进行了一些修改,只将小数点和小数点的图像附加到我总共五个字段的最后两个字段中 下面是我的代码,显示十进制图像并将其附加到输入中:Iphone 在我的数字键盘上加上这个小数点,我遗漏了什么?,iphone,Iphone,过去一周我一直在关注这个问题。无数杯咖啡,猫踩在我的键盘上,还有女朋友希望我以后离开笔记本电脑——我仍然无法理解这一点。希望我在做一些非常愚蠢的事情,100%的几率我看过头了 我有一些代码在数字键盘上加了一个小数。大部分代码都是从这里获取的,我正在使用他的代码,但对其进行了一些修改,只将小数点和小数点的图像附加到我总共五个字段的最后两个字段中 下面是我的代码,显示十进制图像并将其附加到输入中: - (void)textFieldDidBeginEditing:(UITextField *)tex
- (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:@"."];
}
这是正在发生的事情的视频。小数点不会显示,除非我调出警报错误,然后它会正确显示两个字段
因此,我关闭了字段验证,令人震惊的是,小数点显示在最后两个字段上。因此,它一定不是显示小数的代码,而是我得到的验证
这是我得到的验证。我在想我是在文本字段为零的情况下投球,还是作为第一响应者
- (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];
}
}
}
我真的很困惑,但至少我发现这是我的验证把事情搞混了
编辑:
我发现如果我注释掉使下一个字段成为第一响应者的else,那么一切都会正常工作
话虽如此,删除else真的会伤害我的验证吗?当我使用基本键盘时,整个验证都是为了使用“完成”和“下一步”按钮。现在,我发现我的整个验证代码都有点不足:很可能当你打电话时-成为第一响应者,键盘正在被重新绘制,这很可能是将键盘视图推到你神奇的点视图之上,而这个点视图应该是浮在上面的。您可能需要在切换第一响应者时使用点视图调用-bringsubview-tofront: