0

In my app, it causes problems if the 'Next' button (return key) is tapped rapidly. Is there a way I can stop the user from doing this? I can't think of a solution myself.

I am in a UIScrollView with many pages and on a certain page I have a keyboard popup so the user can type into a UITextField. Tapping the next button prompts the scroll view to slide to the next page. However, if the the user taps the button too much it causes the scroll view to jump about.

The code below is when the return key is tapped, the key part is it calls [self setPage:6];

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //Enter your first and last name
    if (textField == firstnameField1) 
    {
        //Put the text into a string to be saved
        firstName1 = firstnameField1.text;
        //Send user to next field (your surname)
        [surnameField1 becomeFirstResponder];
    }
    else if (textField == surnameField1)
    {
        //Put text into a string to be saved
        surname1 = surnameField1.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 4) {
            [self setPage:5];
        }
        else if (pageController.currentPage == 3)
        {
            [self setPage:5];
        }

        currentStage = stage6;
    }

    //Enter your partners first and last name
    if (textField == firstnameField2) 
    {
        //Put the text into a string to be saved
        firstName2 = firstnameField2.text;
        //Send user to next field (your partners surname)
        [surnameField2 becomeFirstResponder];
    }
    else if (textField == surnameField2)
    {
        //Put text into a string to be saved
        surname2 = surnameField2.text;
        //Move to the next stage, enter partners name
        if (pageController.currentPage == 5) {
            [self setPage:6];
        }
        else if (pageController.currentPage == 4)
        {
            [self setPage:6];
        }

        currentStage = stage7;
    }

    return YES;
}

That method setPage is below:

-(void)setPage:(int)destinationPage
{
    //Scroll to appropriate page in scroll view
    CGRect frame = scrollViewController.frame;
    frame.origin.x = frame.size.width * destinationPage;
    frame.origin.y = 0;
    [scrollViewController scrollRectToVisible:frame animated:YES];
}

Thanks.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

1 Answers1

0

From your code, it looks like you're overloading the Return button. Have you considered implementing a toolbar with Next/Previous buttons so that the user can easily return to a skipped field if they accidentally overtap?

Community
  • 1
  • 1
Ben S
  • 68,394
  • 30
  • 171
  • 212