I've been staring at this issue for the past week. Countless cups of Joe, cats stepping on my keyboard, and girlfriend wanting me to get off of the laptop later - I still can't figure this out. Hoping I'm doing something very stupid (100% chance) that I'm over looking.
在过去的一周里,我一直在关注这个问题。无数的乔,猫踩着我的键盘,女朋友想让我在晚些时候离开笔记本电脑——我还是搞不懂。希望我做了一件非常愚蠢的事(百分之百的机会),我已经不再看了。
I have some code which appends a decimal to the number pad. Most of the code was taken from here (http://brygruver.squarespace.com/blog/2009/10/1/creating-a-custom-number-pad.html?lastPage=true&postSubmitted=true) and I'm using his code but modified it a bit to only append the decimal and image of the decimal to the last two fields of my total five fields.
我有一些代码,它将小数附加到数字pad中。大多数代码都是从这里获取的(http://brygruver.squarespace.com/blog/2009/10/1/creating-a-定制的数字pad.html? lastpage= true&postsubmittedtrue),我正在使用他的代码,但修改了一点,只将小数点的小数点和前两个字段的图像添加到我总共5个字段的最后两个字段中。
Here is my code which is showing the decimal image and appending it to the input:
下面是我的代码,它显示了十进制图像,并将其附加到输入:
- (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:@"."];
}
here is a video of what's happening (http://screencast.com/t/OTNhODRiYjAt). The decimal isn't showing unless I bring up the alert error, and then it shows correctly for both the fields.
这里有一个关于正在发生的事情的视频(http://screencast.com/t/OTNhODRiYjAt)。小数点没有显示,除非我提出警告错误,然后它对两个字段都正确显示。
SO, I turned off the field validation and - shocking - the decimal shows on the last two fields (http://screencast.com/t/ZmQyOTc1MT). So it must not be the code showing the decimals but the validation I have.
因此,我关闭了字段验证和——令人震惊的——在最后两个字段(http://screencast.com/t/ZmQyOTc1MT)上的小数显示。所以它不应该是表示小数的代码,而是我的验证。
here is the validation I have. I'm thinking I'm dropping the ball with the text field being nil or being first responder?
这是我的验证。我在想,我是在把球扔到文本框里是nil还是作为第一反应者?
- (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];
}
}
}
I'm really stumped but at least figured out it's something with my validation mixing things up...
我真的被难住了,但至少我觉得我的验证混在一起了……
EDIT: I found out if I comment out the else
that makes the next field the first responder, then everything works as it should.
编辑:我发现如果我注释掉下一个领域的第一个响应者,那么一切都是应该的。
With that said, does removing the else
really hurt anything in my validation? This entire validation was made with the idea of using the 'done' and 'next' buttons back when I was using the basic keyboard. Now, I'm seeing that my entire validation code is lacking a bit :)
这样的话,除去其他东西真的会伤害到我的验证吗?整个验证过程是在我使用基本键盘时使用“done”和“next”按钮的想法进行的。现在,我看到我的整个验证代码都缺少了一点:)
1 个解决方案
#1
0
Most likely when you call -becomeFirstResponder
, the keyboard is getting redrawn, which likely is pushing the keyboard view above your magical "dot" view that is supposed to be floating on top. You probably need to call -bringSubviewToFront:
with your "dot" view whenever you switch first responder.
最可能的情况是,当你调用-成为firstresponder的时候,键盘会被重新绘制,这很可能是将键盘视图推到你的“点”视图之上,而这个视图应该是在顶部浮动的。您可能需要调用-bringSubviewToFront:在切换第一响应器时使用“dot”视图。
#1
0
Most likely when you call -becomeFirstResponder
, the keyboard is getting redrawn, which likely is pushing the keyboard view above your magical "dot" view that is supposed to be floating on top. You probably need to call -bringSubviewToFront:
with your "dot" view whenever you switch first responder.
最可能的情况是,当你调用-成为firstresponder的时候,键盘会被重新绘制,这很可能是将键盘视图推到你的“点”视图之上,而这个视图应该是在顶部浮动的。您可能需要调用-bringSubviewToFront:在切换第一响应器时使用“dot”视图。