开发者

TextField in UITable Scroll on KeyBoard

I have UITextField in UITableView and When I am clicking on the UITextField then I have moved the offset, But My Question is when the user scroll to next field then it show weird behaviour some time input refreshes or the fo开发者_JAVA百科cus will return to previous UITextField.


See this code and impelement According ur project

  • (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    [self scrollViewToCenterOfScreen:textField];
    return YES; }

  • (void)scrollViewToCenterOfScreen:(UIView *)theView {
    CGFloat viewCenterY = theView.center.y;
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

    CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard

    CGFloat y = viewCenterY - availableHeight / 2.0;
    if (y < 0) {
    y = 0;
    }
    [scrollview setContentOffset:CGPointMake(0, y) animated:YES];

}

-(BOOL) textFieldShouldReturn:(UITextField *)textField{

if ([textField isEqual:txtStAppField])
{
    [txtStConfirmField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
    [txtDummyAppField becomeFirstResponder];
}
else if ([textField isEqual:txtStConfirmField])
{
    [txtDummyConfirmFeild becomeFirstResponder];
}
else 
{
    [textField resignFirstResponder];       
    [scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
}

return YES;

}

// txtStConfirmField,txtDummyConfirmFeild,txtDummyAppField,txtStConfirmField,txtStConfirmField are tectField name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜