Rinat
Rinat

Reputation: 598

Selected tableviewCell isn't fully shows after keyboard appears

I have a UiTextView inside a custom UITableViewCell. The keyboard appears when i select a textview.

enter image description here

But sometimes strange behavior occurs :

enter image description here

Selected tableviewCell isn't fully shows after keyboard appears. Any ideas? I have spent 2 days solving this problem, please help.

Upvotes: 0

Views: 198

Answers (2)

Rinat
Rinat

Reputation: 598

In conclusion, i've solved this problem with observing tableView.ContentOffset value.

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (_isScrollingDownLocked) {
        CGPoint newPoint = (CGPoint)[[change valueForKey:NSKeyValueChangeNewKey ] CGPointValue];
        CGPoint oldPoint = (CGPoint)[[change objectForKey:NSKeyValueChangeOldKey] CGPointValue];
        if (newPoint.y<oldPoint.y) {
            CGPoint point = CGPointMake(oldPoint.x, oldPoint.y);
            [self removeObserver:self forKeyPath:@"self.tableView.contentOffset"];
            self.tableView.contentOffset = point;
            [self addObserver:self forKeyPath:@"self.tableView.contentOffset"    options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
        }
    }
}

Upvotes: 0

Dustin
Dustin

Reputation: 6803

You could move the view up when the keyboard is shown

//Add to viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardWillHideNotification object:nil];

//Add to View Controller

//Pushes the view up if one of the table forms is selected for editing
- (void) keyboardDidShow:(NSNotification *)aNotification
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];
    self.view.center = CGPointMake(self.view.center.x, self.view.center.y-moveAmount);
    [UIView commitAnimations];
    isRaised = [NSNumber numberWithBool:YES];
}

//Pushes view back down
- (void) keyboardDidHide:(NSNotification *)aNotification
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.25];
    self.view.center = CGPointMake(self.view.center.x, self.view.center.y+moveAmount);
    [UIView commitAnimations];
    isRaised = [NSNumber numberWithBool:NO];
}

Upvotes: 1

Related Questions