0

I have a footerview in my uitableview that has a uitextfield in it. The problem is that when the user clicks on the uitextfield it pushes up the uitextfield(which is ok) but then there is an awkward gap between the footerview and the keyboard. Here is a picture to illustrate what I'm talking about.enter image description here

Any reason why this is happening?

Here is the relevant code:

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 50;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{


    MSChatFooter *footer = [[[NSBundle mainBundle] loadNibNamed:@"MSChatFooter" owner:self options:nil] firstObject];

    return footer;


}
shreyashirday
  • 892
  • 1
  • 10
  • 34

1 Answers1

0

This isn't fully tested but I think you need something like this

@property (strong, nonatomic) MSChatFooter *chatFooter;

- (void)viewDidLoad
{
    //Table Initialization
    ...

    chatFooter = [[[NSBundle mainBundle] loadNibNamed:@"MSChatFooter" owner:self options:nil] firstObject];
    UIView *footerView = [UIView new];
    footerView.frame = chatFooter.frame;
    [footerView addSubview:chatFooter];

    self.tableView.tableFooterView = footerView;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                     selector:@selector(keyboardWasShown:)
                                         name:UIKeyboardDidShowNotification
                                       object:nil];
}

- (void)keyboardWasShown:(NSNotification *)notification
{

    // Get the size of the keyboard.
    CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    //Given size may not account for screen rotation
    int height = MIN(keyboardSize.height,keyboardSize.width);
    int width = MAX(keyboardSize.height,keyboardSize.width);

    self.tableView.frame = CGRectMake(0, 0, self.view.bounds.width, self.view.bounds.height - height);
}

Credit to Get the frame of the keyboard dynamically for keyboard code

Community
  • 1
  • 1
mverderese
  • 5,314
  • 6
  • 27
  • 36