Question

I am trying to add a footer to my table view. The problem I'm having is:

If I set the footer in viewWillLayoutSubviews, then that causes viewWillLayoutSubviews to be called and we end up in an infinite loop.

If instead I set the footer in viewDidLoad and calculate it and its subviews' frames in viewWillLayoutSubviews, the footer ends up at the top of the table view covering up my first section.

I can't calculate the frames in viewDidLoad because the table view's bounds aren't right then (my app only supports landscape mode).

I can use a boolean instance variable to create and layout the footer view in viewWillLayoutSubviews but only when it's first called, but that seems wrong. Then the frames won't ever be calculated again. There must be a better way.

Était-ce utile?

La solution

Just create them in viewDidLoad and assign them to the tableViewHeader and tableViewFooter properties, that way the tableview will handle their positioning.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top