Ich hoffe , euch hat schon eine Lösung all diejenigen zu lesen. Aber ich fand meine Lösung wie folgt. Ich erwarte , dass Sie bereits eine Zelle haben mit UITextField. Also auf der Vorbereitung nur hält den Zeilenindex in das Tag-Textfeld ein .
cell.textField.tag = IndexPath.row;
Erstellen Sie ein activeTextField, Instanz UITextFieldmit globaler Reichweite wie folgt:
@interface EditViewController (){
UITextField *activeTextField;
}
So, jetzt nur Sie kopieren meinen Code am Ende einfügen. Und auch nicht vergessen, hinzuzufügen,UITextFieldDelegate
#pragma mark - TextField Delegation
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
activeTextField = textField;
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
activeTextField = nil;
}
Register Tastatur 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];
}
Griffe Keyboard Notifications:
Wird aufgerufen , wenn die UIKeyboardDidShowNotificationgesendet wird.
- (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];
}
Wird aufgerufen , wenn die UIKeyboardWillHideNotificationgesendet wird ,
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
}
Jetzt eine Sache bleibt, Rufen Sie das registerForKeyboardNotificationsVerfahren um ViewDidLoadVerfahren wie folgt:
- (void)viewDidLoad {
[super viewDidLoad];
// Registering keyboard notification
[self registerForKeyboardNotifications];
// Your codes here...
}
Sie fertig sind, hoffen , dass Ihr textFieldsnicht mehr von der Tastatur versteckt.