Spero che abbiate già una soluzione per leggere tutti quelli. Ma ho trovato la mia soluzione come segue. Mi aspetto che tu abbia già una cella con UITextField. Quindi, preparandoti, tieni l'indice di riga nel tag del campo di testo.
cell.textField.tag = IndexPath.row;
Creare activeTextFieldun'istanza di UITextFieldambito globale come di seguito:
@interface EditViewController (){
UITextField *activeTextField;
}
Quindi, ora copia e incolla il mio codice alla fine. E inoltre, non dimenticare di aggiungereUITextFieldDelegate
#pragma mark - TextField Delegation
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
activeTextField = textField;
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
activeTextField = nil;
}
Registra la tastiera 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];
}
Tastiera delle maniglie Notifications:
Chiamato quando UIKeyboardDidShowNotificationviene inviato.
- (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];
}
Chiamato quando UIKeyboardWillHideNotificationviene inviato
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
}
Ora rimane solo una cosa, chiama il registerForKeyboardNotificationsmetodo nel ViewDidLoadmetodo come segue:
- (void)viewDidLoad {
[super viewDidLoad];
// Registering keyboard notification
[self registerForKeyboardNotifications];
// Your codes here...
}
Hai finito, spero che la tua textFieldsvolontà non sia più nascosta dalla tastiera.