4

I have a UITextField inside a UIView which is used as the tableHeaderView of a UITableView.

When I call resignFirstResponder for the textField in order to dismiss the keyboard, the whole tableHeaderView vanishes. Same happens when I try to reload the data of the tableview while the keyboard is up.

Any ideas why?

EDIT: Sample code

UITableViewCell *header = [self.tableView dequeueReusableCellWithIdentifier:@"mapViewCell"];
UITextField *searchField = [header viewWithTag:6];
searchField.delegate = self;
self.tableView.tableHeaderView = header;

and in a delegate method for textfield:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [searchField resignFirstResponder];
    return YES;
}

Keyboard is dismissed but the whole tableHeaderView goes away (turns into white)

giorgos.nl
  • 2,704
  • 27
  • 36

2 Answers2

5

I solved it by wrapping the UITableViewCell used as tableHeaderView inside a UIView:

UIView *view = [[UIView alloc] initWithFrame:[header frame]];
[view addSubview:header];
self.tableView.tableHeaderView = view;
giorgos.nl
  • 2,704
  • 27
  • 36
1

In swift 3,

let view : UIView = UIView.init(frame: (header?.frame)!)
view.addSubview(h)
tableView.tableHeaderView = view
iroiroys
  • 788
  • 1
  • 10
  • 17