Espero que ya tengan una solución para leer todos esos. Pero encontré mi solución de la siguiente manera. Espero que ya tengas una celda UITextField. Entonces, al prepararse, simplemente mantenga el índice de la fila en la etiqueta del campo de texto.
cell.textField.tag = IndexPath.row;
Cree una activeTextFieldinstancia de UITextFieldcon alcance global como se muestra a continuación:
@interface EditViewController (){
UITextField *activeTextField;
}
Entonces, ahora solo copia y pega mi código al final. Y tampoco olvides agregarUITextFieldDelegate
#pragma mark - TextField Delegation
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
activeTextField = textField;
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
activeTextField = nil;
}
Registra el teclado notifications
#pragma mark - Keyboard Activity
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
Maneja el teclado Notifications:
Llamado cuando UIKeyboardDidShowNotificationse envía el.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
NSIndexPath *currentRowIndex = [NSIndexPath indexPathForRow:activeTextField.tag inSection:0];
[self.tableView scrollToRowAtIndexPath:currentRowIndex atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Se llama cuando UIKeyboardWillHideNotificationse envía
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
}
Ahora queda una cosa, llame al registerForKeyboardNotificationsmétodo al ViewDidLoadmétodo de la siguiente manera:
- (void)viewDidLoad {
[super viewDidLoad];
// Registering keyboard notification
[self registerForKeyboardNotifications];
// Your codes here...
}
Ya terminaste, espero que tu textFieldsteclado ya no esté oculto.