Scroll the table view to an overflow text box when the keyboard lights up with a text box inside the popup

I have a UITableViewController with many cells, each cell contains four text fields vertically from each other, the pop file is represented by clicking on any text field, however this pop content contains a text field when you press the keyboard and most likely the pop file will be shifted. so that the keyboard does not hide its text field (this is the default behavior), but in the background (dim view) tableViewController loses proper scrolling to keep the textField popup on the track while the keyboard is visible.

here you can download an example project .

how can I compensate for the presentation of the table in order to keep the present-textField popup on the screen while the keyboard is visible in this case?

I tried the famous TPKeyboardAvoiding library, but this did not solve the problem.

ps tableViewController works well for the first 3 or 4 keyboard crashes, but loses precise scrolling on subsequent attempts.

Screenshot (the green text field is a text field that displays a pop-up window, but tableViewController scrolls to the wrong text field indicated in red): enter image description here

Any help would be greatly appreciated.

EDIT: this question is not a duplicate for: Performing a UITableView scroll when selecting a text field because the text field that I need to view the table to scroll is the one that calls pop music not on the keyboard, and scrollToRowAtIndexPath does not work exactly in this case , because each cell contains 4 text fields.

+8
ios objective-c iphone uitableview
source share
5 answers

use (CGRect) convertRect: (CGRect) rect toView: (UIView *) view to get cell position in viewviews viewview and handle table offset accordingly

+2
source share

Here is my solution: Go to TableViewController.m

1. Registration for the Notification Keyboard ( UIKeyboardWillShowNotification, UIKeyboardWillHideNotification )

2. Create local variables:

 CGSize _currentPopoverContentSize; //if you want to have custom size for popover UIView *_currentPopoverSender; //to remember from wich view you will present popover BOOL _keyboardIsShown; //enable in keyboardWillShow, and disable in keyboardWillHide 

3. In my currentPopover method:

 - (void)presentPopoverControllerWithSize:(CGSize)size fromView:(UIView *)sender{ MyController *controller = [[[MyController alloc] init] autorelease]; if (self.popover) { [_popover release]; _popover = nil; } _popover = [[UIPopoverController alloc] initWithContentViewController:controller]; _popover.popoverContentSize = size; _popover.delegate = self; //checking if keyboard is shown - if NO, than present popover, if YES - just `resignFirstResponder` for your _`activeTextField`(you can set it in -textFieldDidBeginEditing: and nullify in -textFieldDidEndEditing:) if (!_keyboardIsShown) { [_popover presentPopoverFromRect:[sender bounds] inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; _popOver.popoverContentSize = CGSizeMake(320, 700); } else { [_activeTextField resignFirstResponder]; } _currentPopoverContentSize = size; _currentPopoverSender = sender; } 

4. What:

 - (void)keyboardWillBeHidden:(NSNotification*)aNotification{ [UIView animateWithDuration:0.3 animations:^{ //do some stuff _popOver.popoverContentSize = CGSizeMake(320, 700); } completion:^(BOOL finished) { if (_popover && _currentPopoverSender) { [_popover presentPopoverFromRect:[_currentPopoverSender bounds] inView:_currentPopoverSender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } }]; _keyboardIsShown = NO; } 

5 .:

 -(void)textFieldDidBeginEditing:(UITextField *)textField{ [textField resignFirstResponder]; [self presentPopoverControllerWithSize:textField.frame.size fromView:_activeText]; // self.vc = [[self storyboard] instantiateViewControllerWithIdentifier:@"ProductSourcePopOver"]; // // if(_popOver == nil){ //make sure popover isn't displayed more than once in the view // _popOver = [[UIPopoverController alloc]initWithContentViewController:self.vc]; // } // _popOver.popoverContentSize = CGSizeMake(320, 700); // // [_popOver presentPopoverFromRect:_activeText.frame inView:_activeText permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; // _popOver.delegate = self; } 

This may help you :)

+1
source share

Resize the entire view frame.

For example, keyboard height is 100 , then

 CGRect frame = self.view.frame; self.view.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height - keyboardHeight); 

Then call the didSelectRowAtIndexPath method again for the same indexPath so that it reloads the popover.

This is just a basic idea, some changes may be required to achieve accurate behavior.

Hope this helps you.

0
source share

How about adding a tag (00 01 02 03, 10 11 12 13 ... etc.) for each UIText field in the cell. From dozens of digits you can find out which cell, from the individual digits that you know in which text box.

0
source share

Register for UIKeyboardWillShowNotification and when this selector is activated, call your pop code:

 [self presentPopoverControllerWithSize:textField.frame.size fromView:_activeText]; 

The reason for this is that iOS processes itself by introducing a popover and processing its frame. Therefore, it is generally recommended that you display tooltips after showing the keyboard.

Hope this helps.

0
source share

All Articles