Anshuk Garg
Anshuk Garg

Reputation: 1540

content inset to move the table view when keyboard appears

im stuck with a simple issue of moving my tableview when the keyboard shows. i dont want to move the frame using animations, instead i want to use content inset to move the table view.

my notification is being called bt it doesnt move the tableview.

- (void)keyboardWillShow:(NSNotification *)notification {
NSLog(@"%@",self.tableView1);

    NSValue *keyboardBoundsValue = [[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey];

    CGRect keyboardBounds;
    [keyboardBoundsValue getValue:&keyboardBounds];
    UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0);
NSLog(@"%d %d %d %d",self.tableView1.contentInset.bottom,self.tableView1.contentInset.top,self.tableView1.contentInset.left,self.tableView1.contentInset.right);    
    [self.tableView1 setContentInset:e];
    [self.tableView1 setScrollIndicatorInsets:e];
    NSLog(@"%d %d %d %d",self.tableView1.contentInset.bottom,self.tableView1.contentInset.top,self.tableView1.contentInset.left,self.tableView1.contentInset.right);

NSLog(@"%@",self.tableView1);
NSLog(@"keyboard notification");
}

Upvotes: 3

Views: 3507

Answers (1)

Demz
Demz

Reputation: 1058

What I believe you try to do here is making the scroll area of the table smaller in order to not have the keyboard overlap the table. In that case, maybe you should put

UIEdgeInsets e = UIEdgeInsetsMake(0, 0, keyboardBounds.size.height, 0);

instead of keyboardBounds.size.width. If you want to "move" the table, then you can do that only by modifying its frame.origin or its center.

Upvotes: 2

Related Questions