iPhone scrolling the view up when keyboard is open
- by Rob
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?