Я надеюсь , что вы , ребята , уже есть решение для чтения всех тех. Но я нашел свое решение следующим образом . Я ожидал , что у вас уже есть ячейки с UITextField. Так что на подготовку просто держать индекс строки в теге текстового поля.
cell.textField.tag = IndexPath.row;
Создать activeTextField, экземпляр UITextFieldс глобальной областью , как показано ниже:
@interface EditViewController (){
UITextField *activeTextField;
}
Итак, теперь вы просто скопировать вставить свой код в конце. А также не забудьте добавитьUITextFieldDelegate
#pragma mark - TextField Delegation
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
activeTextField = textField;
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
activeTextField = nil;
}
Регистры клавиатуры 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];
}
Ручки клавиатуры Notifications:
Вызывается , когда UIKeyboardDidShowNotificationпосылается.
- (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];
}
Вызывается , когда UIKeyboardWillHideNotificationпосылается
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
}
Теперь одна вещь остается, вызовите registerForKeyboardNotificationsметод и ViewDidLoadметод следующим образом :
- (void)viewDidLoad {
[super viewDidLoad];
// Registering keyboard notification
[self registerForKeyboardNotifications];
// Your codes here...
}
Вы сделали, надеюсь , что ваша textFieldsволя больше не скрыты с помощью клавиатуры.