views:

37

answers:

2

I have 8 text fields in the table view. I need to enter the data into that text fields in both Portrait and Landscape mode. some text fields are back side of the Key board.I am unable to enter data into that text fields.

I have done in portrait mode with help of willShowKeyBoard notification and working fine.But, Same thing i have applied to Landscape mode but it doesn't working fine. How to move the table view upwards to enter the data in the text fields?

  • (void)keyboardWillShow:(NSNotification *)notif {

    if ([NameField isFirstResponder] && myView.frame.origin.y >= 0)
    {       
    
    
    }
    else if([credentialField isFirstResponder] && myView.frame.origin.y >=0)
    {
    
    
    }
    else if([specialityField isFirstResponder] && myView.frame.origin.y >=0)
    {
    
    
    }
    else if([streetField isFirstResponder] && myView.frame.origin.y >=0)
    {
        [self setViewMovedUp:YES];
    }
    else if([cityField isFirstResponder] && myView.frame.origin.y >=0)
    {
        [self setViewMovedUp:YES];
    }
    else if([stateField isFirstResponder] && myView.frame.origin.y >=0)
    {
        [self setViewMovedUp:YES];
    }
    else if([zipcodeField isFirstResponder] && myView.frame.origin.y >=0)
    {
        [self setViewMovedUp:YES];
    }
    

}

-(void)setViewMovedUp:(BOOL)movedUp { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; // if you want to slide up the view CGRect rect = myView.frame; if (movedUp) {
rect.origin.y = rect.origin.y - kOFFSET_FOR_KEYBOARD1; rect.size.height = rect.size.height + kOFFSET_FOR_KEYBOARD1; } else { rect.origin.y = rect.origin.y + kOFFSET_FOR_KEYBOARD1; rect.size.height = rect.size.height - kOFFSET_FOR_KEYBOARD1; }

myView.frame=rect;
[UIView commitAnimations];

}

A: 

I do not know if you already use this, but take a look here: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TextandWeb/TextandWeb.html#//apple_ref/doc/uid/TP40007072-CH20-SW7

It is explained how it works, and it is doing fine. It should work also in lanscape mode, because it looks how many pixels the keyboard has and push the content upwards.

Best regards Tim

Tim
A: 

You should use a UIScrollView to do that, you can then move your content up/down.

CiNN