iPhone键盘快速点击“下一步”按钮

时间:2012-01-10 21:03:36

标签: iphone objective-c ipad uikeyboard

在我的应用中,如果快速点击“下一步”按钮(返回键),则会导致问题。有没有办法阻止用户这样做?我自己也想不出解决方案。

我在UIScrollView中有很多页面,在某个页面上我有一个键盘弹出窗口,因此用户可以键入UITextField。点击下一个按钮会提示滚动视图滑动到下一页。但是,如果用户点击按钮太多,则会导致滚动视图跳转。

下面的代码是点击返回键时,关键部分是调用[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;
}

该方法setPage如下:

-(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];
}

感谢。

1 个答案:

答案 0 :(得分:0)

从您的代码中,您看起来正在重载“返回”按钮。您是否考虑过实施toolbar with Next/Previous buttons,以便用户可以轻松返回跳过的字段?