Bharat
Bharat

Reputation: 3007

Scrolling a tableview for enter text in textfield?

I found many other threads discussed about this problem, but none of them works for me. My scenario is that i've a UITableViewController and custom UITableViewCell with UITextField on it.text field appears with long press(UILongPressGestureRecognizer) and it become first responder.

- (void) textFieldDidBeginEditing:(UITextField *)textField {
      NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
    //self.tableView.contentSize = CGSizeMake(self.tableView.frame.size.width, 600);
    [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

point is calculated CGPoint point = [gestureRecognizer locationInView:self.tableView]; But it did not scroll the table view. What i'm doing wrong?Any suggestion or sample code would be appreciated.

Upvotes: 2

Views: 290

Answers (1)

Naveen kumar
Naveen kumar

Reputation: 800

Add this code in textFieldDidBeginEditing method. Its working fine in my application.Now i am able to enter text for all tableview textfields.

        CGPoint offset = CGPointMake(0, selectedCellIndexPath.row * ROW_SIZE);
        [self.tableViewObj setContentOffset:offset animated:YES];

Upvotes: 2

Related Questions