I have a UITableView for which I dynamically set the Frame in order to size it to the number of items. I’m doing this so the tableview can be “slid” down via a drag from the top of the phone. The UITableView is defined within a nib for the view.
Whenever the view which contains this sliding UITableView disappears (as in, viewDidDisappear is invoked), the UITableView’s Frame gets reset to the value in the nib (which I’ve set as 44, the size of the static footer).
My question is two part:
- Why does the Frame get reset, and what mechanism is resetting the Frame?
- How might I ensure that whenever the Frame gets reset to the nib value, that I can set the Frame to the size that I want?
For background, I’ve exhausted every plausible view lifecycle method.
An interesting note is that I tried to set the Frame in ViewDidAppear, which gets hit in reproducing my “bug” and for which I’ve verified the Frame.Height is the desired value at the end of the method, though when the pins fall at the end the Frame height is still at 44. Is the tableView IBOutlet I’m hitting not the one that is actually loaded in the view?
public override void ViewDidAppear (bool animated)
{
RetractMemoryTableAnimation(0);
// Frame is correct after this line (Height > 44)
// But the Frame in my view persists to a height of 44
this.tableView.Frame = new RectangleF(this.tableView.Frame.Location.X, this.tableView.Frame.Location.Y,
this.tableView.Frame.Size.Width, this.CalculatedTableViewHeightWithFooter);
}
When writing custom code to set a
UIView‘s frame, always make sure to setAutoresizingMasktoUIAutoresizingMask.Noneif the view seems to be getting auto-resized.