-1

I have UITableView and inside that TableView I have a custom cell which contains label and textfield. Now when I use keyboardNotifier (keyboard arises) and when i tap on one textfield and then without pressing return button I tap on another textfield it adds the space between the first textfield to keyboard and second textfield to keyboard i.e it sums the space for both the textfield and it scrolls to top with lot of space between the textfields. Can anyone tell me what i can do to maintain constant proper distance between textfields.

Here is my code:

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

    CGRect frame = [RegisterTableVIew frame]; //RegisterTableVIew is  tableview
    frame.size.height -= 200; 
    [RegisterTableVIew setFrame:frame];
keyboardStatus = YES;

}

-(void) keyboardWillHide:(NSNotification *)note
{
   CGRect frame = [RegisterTableVIew frame]; //RegisterTableVIew is  tableview
    frame.size.height += 200; 
    [RegisterTableVIew setFrame:frame];

    keyboardStatus = NO;
}
Jeet Kapadia
  • 31
  • 1
  • 7
  • I wouldn't reframe the table view (especially with a literal 200px, which is certain to cause problems across devices and rotations). Instead, scroll the cell with the text field into position. Read through this http://stackoverflow.com/questions/594181/making-a-uitableview-scroll-when-text-field-is-selected, paying special attention to this answer http://stackoverflow.com/a/751454/294949. – danh Mar 27 '17 at 15:08

2 Answers2

1

i dont get it clearly, btw this my be helpful!

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(![_Search resignFirstResponder])
    {
        [_Search resignFirstResponder];
    }
    else
    {

    }
    [super touchesBegan:touches withEvent:event];
}
excitedmicrobe
  • 2,338
  • 1
  • 14
  • 30
0

Try this;

-(void)keyboardNotifier:(NSNotification *)notification {
  if(keyboardStatus == NO) {
    CGRect frame = [RegisterTableVIew frame]; //RegisterTableVIew is  tableview
    frame.size.height -= 200; 
    [RegisterTableVIew setFrame:frame];
    keyboardStatus = YES;
  }
}

-(void) keyboardWillHide:(NSNotification *)note
{
 if(keyboardStatus) {
   CGRect frame = [RegisterTableVIew frame]; //RegisterTableVIew is  tableview
    frame.size.height += 200; 
    [RegisterTableVIew setFrame:frame];
    keyboardStatus = NO;
  }
}

I answerwed from what i understood from your question that each time you click on textfield, tableView scrolls up creating lot of space.

nikdange_me
  • 2,949
  • 2
  • 16
  • 24