tags:

views:

36

answers:

1

I am using two forms of text validation (one when they click Next, another when they manually select the next text field to enter) and it's been working perfect. However, the last text field isn't getting error checked and I can't figure it out.

You can see the issue in this video on the last text field (http://screencast.com/t/ODJiOTAwMzA). The previous four work fine as you can see, but the bottom not so much.

Here is my code:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == txtUserName)
    {
        NSString *userNameOne = txtUserName.text;
        double numOne = [userNameOne doubleValue];  

        if(numOne < 30 || numOne > 80)
        {

            //foo

            [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)
        {
            //foo

            [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)
        {
            //foo

            [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)
        {

                        //foo

            [txtUserName4 becomeFirstResponder];
            txtUserName4.text = nil;
        }
        else
        {
            [txtUserName5 becomeFirstResponder];
        }
    }

    else if (textField == txtUserName5)
    {
        NSString *userNameFive = txtUserName5.text;
        double numFive = [userNameFive doubleValue];

        if (numFive > 1)
        {
                        //foo

        }
    }
    return NO;
}

and here

if (textField == txtUserName)
    {
        NSString *userNameOne = txtUserName.text;
        double numOne = [userNameOne doubleValue];  

        if(numOne < 30 || numOne > 80)
        {

                        //foo

            [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)
        {

                        //foo

            [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)
        {
            //fo

            [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)
        {

            //foo

            [txtUserName4 becomeFirstResponder];
            txtUserName4.text = nil;
        }
        else
        {
            [txtUserName5 becomeFirstResponder];
        }
    }
    else if (textField == txtUserName5)
    {
        NSString *userNameFive = txtUserName5.text;
        double numFive = [userNameFive doubleValue];

        if (numFive > 1)
        {
            //foo
        }
        else
        {
            [txtUserName5 becomeFirstResponder];
        }
    }
A: 

If your interface is in Interface Builder, is the outlet for txtUserName5 hooked up?

For your fifth text field, why don't you have these lines after "foo" like you do for the other text fields?

if (numFive > 1)
{
    //foo
    [txtUserName5 becomeFirstResponder];
    txtUserName5.text = nil;
}

Also, for your else clause, rather than become first responder again, you should resign first responder (to dismiss the keyboard):

else
{
    //[txtUserName5 becomeFirstResponder];
    [txtUserName5 resignFirstResponder];
    return YES;
}
gerry3
thanks for responding. I can def look into the issues you pointed out, but this still doesn't help my issue of the fifth text field not being validated. Also, the fifth text field is hooked up into IB as you can see here (http://screencast.com/t/NWE5NGI3NTM). I appreciate any help you can provide.
HollerTrain
Set a breakpoint and/or use NSLog. Is your validation code getting hit? What are the values in the comparison?
gerry3
thanks for your continued help. Here is a video of it showing that the previous fields work with setting breakpoints, yet when I set it to the last field it does nothing, which is making this even stranger for me. (http://screencast.com/t/NjY2MjMyM2Q)
HollerTrain
Is the last field's delegate set?
gerry3
GERRY3 YOU SAVED MY ENTIRE DAY!!!! I LOVE YOU AND WANT TO HAVE CODE BABIES WITH YOU!!!
HollerTrain