I have a UITextField as a table on a UIViewController (not a UITableViewController ). If the table view is on the UITableViewController , the table automatically scrolls to the editable textField to prevent it from being hidden from the keyboard. But on a UIViewController this is not the case.
I tried a couple of days, reading several ways to try to do this, and I can't get it to work. The closest thing that actually scrolls:
-(void) textFieldDidBeginEditing:(UITextField *)textField {
However, this only scrolls the table to the very top row. A simple task seems to be a couple of days of frustration.
To build tableView cells, I use the following:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *identifier = [NSString stringWithFormat: @"%d:%d", [indexPath indexAtPosition: 0], [indexPath indexAtPosition:1]]; UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(180, 10, 130, 25)]; theTextField.adjustsFontSizeToFitWidth = YES; theTextField.textColor = [UIColor redColor]; theTextField.text = [textFieldArray objectAtIndex:indexPath.row]; theTextField.keyboardType = UIKeyboardTypeDefault; theTextField.returnKeyType = UIReturnKeyDone; theTextField.font = [UIFont boldSystemFontOfSize:14]; theTextField.backgroundColor = [UIColor whiteColor]; theTextField.autocorrectionType = UITextAutocorrectionTypeNo; theTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; theTextField.clearsOnBeginEditing = NO; theTextField.textAlignment = UITextAlignmentLeft;
I suspect I can get tableView to scroll correctly if I can somehow pass indexPath.row in the textFieldDidBeginEditing method?
Any help is appreciated.
uitextfield xcode uitableview keyboard
Lauren Quantrell Mar 10 2018-11-11T00: 00Z
source share