bibscy bibscy - 1 year ago 151
Swift Question

call function before tableView:viewForHeaderInSection: is called - Swift

I have set up a tableView in a ViewController. This table view has 1 section, 2 prototype cells: one is used to return the number of rows in section, the other one is used to display a custom header.

  • In
    function is called to retrieve the data from NSUserDefaults. This data will be used in
    to populate the labels in the header section.
    The problem is that
    is automatically called before
    is called, as a consequence the labels in header section are not populated with the data retrieved from NSUserDefaults.
    How can I call
    is called?

Answer Source

This is a common problem — the data is not ready when the table view first appears. Simply give correct answers to the questions that the table view data source and delegate are asked, given the current state of things; if you have no data, say that there are no sections, for example. When you do have data, call reloadData on the table view to get the questions to be asked again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download