问题
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

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.

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

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?
回答1:
Maybe it needs constraints updating somewhere, or layoutIfNeeded
. Other solution could be found in my other answer.
回答2:
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;
}
来源:https://stackoverflow.com/questions/22983366/autolayout-uilabel-height-changes-on-second-view-appearence