iPhone scrolling the view up when keyboard is open

Posted by Rob on Stack Overflow See other posts from Stack Overflow or by Rob
Published on 2010-05-11T18:06:05Z Indexed on 2010/05/11 19:54 UTC
Read the original article Hit count: 188

Filed under:
|
|

I understand that this problem is incredibly common and I have read through quite a few answers but am having trouble understanding how the code works. This works:

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
if ([sender isEqual:txtLeaveAddyLine1])
{
    //move the main view, so that the keyboard does not hide it.
    if  (self.view.frame.origin.y >= 0)
    {
        [self setViewMovedUp:YES];
    }
} 
}

In this example, txtLeaveAddy is the very first UITextField that is hidden by the keyboard and it works like a charm. As I cycle through the text fields on the screen it scrolls up when the user enters into that txtLeaveAddyLine1 field. However, when I try to add the fields below the txtLeaveAddyLine1 field - nothing happens. For example:

-(void)textFieldDidBeginEditing:(UITextField *)sender
{
    if ([sender isEqual:txtLeaveAddyLine1])
    {
        //move the main view, so that the keyboard does not hide it.
        if  (self.view.frame.origin.y >= 0)
        {
            [self setViewMovedUp:YES];
        }
    } 
    if ([sender isEqual:txtLeaveAddyLine2])
    {
        //move the main view, so that the keyboard does not hide it.
        if  (self.view.frame.origin.y >= 0)
        {
            [self setViewMovedUp:YES];
        }
    } 
}

Am I not using this function correctly?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about scrolling