1

I have a dynamic UILabel in a TableHeaderView (see this question) and everything is okay and fine, but if I set the text of the label to nil or @"" the label keeps the size of the height that it had when the text was in.

I'm changing the text in a different viewController that I'm presenting modally. So i would like to show it you in 3 steps:

Original state

State one

After setting the text to @""

In this step I presented the viewController to remove the text and then I dismiss the viewController to go back to this View.

State two

Reappear this View

So I have to open the editing viewController to just dismiss it again. Then it is like i want it to..:

State three

Any ideas why? I'm re-sizing the TableViewHeader like this in the viewWillAppear method:

- (void)resizeTableViewHeader
{
    //GET THE SIZE OF THE CONTAINER
    CGSize fittingSize = [self.header systemLayoutSizeFittingSize: UILayoutFittingCompressedSize];
    self.header.frame = CGRectMake(0, 0, 320, fittingSize.height);
    self.tableView.tableHeaderView = self.header;
}

Any idea why I have to visit the View twice?

Community
  • 1
  • 1
SaifDeen
  • 862
  • 2
  • 16
  • 33

2 Answers2

0

Maybe it needs constraints updating somewhere, or layoutIfNeeded. Other solution could be found in my other answer.

Community
  • 1
  • 1
MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55
-1

You should implemente the tableViewDelegate method and calculate the header height.

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    CGFloat height = //Calculate the dynamic height.
    return height;
}
Mohd Iftekhar Qurashi
  • 2,385
  • 3
  • 32
  • 44