0

in my table I use cells with UITextField as subview. I also can edit it but only for the upper cells in the table I also see, what I edit, because the keyboard hides the lower cells.

Now what must I do, to scroll the cell I whant to edit move to the top?

I tried

selectRowAtIndexPath:indexPathOfCurrrentCell animated:NO scrollPostion:UITableViewSchrollPositionTop

and

scrollToRowAtIndexPath:idexPathOfCurrentCell atScrollPosition:UITableViewSchrollPositionTop animated:NO

but none of it works. Must I use an other command or add something additional? What must I change?

Thanks

user1075871
  • 75
  • 1
  • 1
  • 5

4 Answers4

2

If you can't manually scroll the tableView to somewhere where the cell is visible; the code won't either.

The solution is to set the frame of the tableView to have a height that respects the keyboard's height of 170 points.

You could try something like this:

tableView.frame = CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.frame.size.height-170);

Do this in your method which gets called when the textField becomes the first responder.

Jack Greenhill
  • 10,240
  • 12
  • 38
  • 70
0

Take a look at this post. I think you'll find what you need.

Get UITableView to scroll to the selected UITextField and Avoid Being Hidden by Keyboard

Community
  • 1
  • 1
Mikayil Abdullayev
  • 12,117
  • 26
  • 122
  • 206
0

Use Delegate Method of UITextField

Muhammed Ayaz
  • 111
  • 1
  • 9
0

Even I encountered this scrolling problem and i use the below logic to get rid of this. This Works fine

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
  if (textField==textFieldOfYourInterest ) 
  {
    CGRect frame = self.view.frame;
      if ([textField isFirstResponder] && self.view.frame.origin.y >= 0)
      {
        frame.origin.y -= 70;
      }
      else if (![textField isFirstResponder] && self.view.frame.origin.y < 0)
      {
        frame.origin.y += 70;
      }

      [self.view setFrame:frame];
  }

}

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

   CGRect frame = self.view.frame;

   if (![topTextFieldName isFirstResponder] && self.view.frame.origin.y < 0)
   {
    frame.origin.y += 70;
   }

   [self.view setFrame:frame];

   NSLog(@"text field should return");
   [textField resignFirstResponder];

   return YES;
}

If any problem revert to me.

Thanks Nagaraja Sathe

Sathe_Nagaraja
  • 163
  • 1
  • 9