I have searched stack overflow (Getting row of UITableView cell on button press) and have found many solutions that people claim to work but I have yet to find the perfect solution. I am trying to get the indexPath of the next/previous UITextField within my UITableView using a CGPoint so that I can scroll to it and make it first responder. Most of the time it is correct however if my text field is a previous field high up in the UITableView in another section I get the wrong result.
Here is the code (Note: nextTxtField is a UIView):
CGPoint point = [nextTxtField convertPoint:CGPointZero toView:tableView];
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:point];
[UIView animateWithDuration:0.03 delay:0.0 options:0 animations:^{
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
} completion:^(BOOL finished) {
dispatch_async(dispatch_get_main_queue(), ^(void){
[nextTxtField becomeFirstResponder];
});
}];