When you click on a text field inside a cell, you need to know the current index path of the cell, so when the keyboard is displayed, you can focus it.
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField { UITableViewCell *cell = (UITableViewCell *)[textField superview].superview; NSIndexPath *idxPath = [table indexPathForCell:cell]; selectedIndex = idxPath.row;
Also add the following line to ViewDidLoad , meaning to watch when the keyboard appears. If you use UIKeyboardWillShowNotification , keyboardWillShow will be called first, followed by textFieldShouldBeginEditing: which is incorrect.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
and install
textfield.delegate = self;
in cellForRowAtIndexPath when creating a text field. It will call the required methods.
source share