Doufám, že vy už mám řešení čtení všech těch. Ale našel jsem řešení takto. Čekám, že již máte buňku UITextField. Takže na přípravu jen držet index řádku do tagu textového pole.
cell.textField.tag = IndexPath.row;
Vytvořit activeTextField, instanci UITextFields globálním rozsahem jak je uvedeno níže:
@interface EditViewController (){
UITextField *activeTextField;
}
Tak, teď stačí zkopírovat vložit svůj kód na konci. A také nezapomeňte přidatUITextFieldDelegate
#pragma mark - TextField Delegation
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
activeTextField = textField;
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
activeTextField = nil;
}
registry klávesnice 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];
}
Kliky klávesnice Notifications:
Volána, když UIKeyboardDidShowNotificationje poslal.
- (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];
}
Volána, když UIKeyboardWillHideNotificationje odeslána
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
[self.tableView setContentInset:contentInsets];
[self.tableView setScrollIndicatorInsets:contentInsets];
}
Nyní jedna věc zbývá, volejte registerForKeyboardNotificationsmetodu k ViewDidLoadmetodě takto:
- (void)viewDidLoad {
[super viewDidLoad];
// Registering keyboard notification
[self registerForKeyboardNotifications];
// Your codes here...
}
Co jste udělal, doufám, že vaše textFieldsvůle už není skryta klávesnice.