2

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.

Bharat
  • 2,987
  • 2
  • 32
  • 48
  • Are you sure you did check this: http://stackoverflow.com/a/6354426/1262634 – Tarek Hallak Dec 04 '13 at 05:59
  • yes, i did, but no luck. – Bharat Dec 04 '13 at 06:03
  • I think [gestureRecognizer locationInView:self.tableView] won't return the right offset of the cell. Did you print out the point value? My suggestion is associate indexPath with textField, and you can make sure you always get the right indexPath. – yibuyiqu Dec 04 '13 at 06:30
  • i tested it and it gives me right indexpath, however i also tried to get indexPath associated with textfield but still no luck. – Bharat Dec 04 '13 at 06:33

1 Answers1

2

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];
Naveen kumar
  • 800
  • 1
  • 5
  • 23
  • You also set becomeFirstResponder property of textFiled when create textfieldObj. [testFieldObj becomeFirstResponder]; – Naveen kumar Dec 04 '13 at 07:08