My app uses three table views on the main screen. I am calling CoreData methods to retrieve that data at start up. I have the dataHelper data object property declared at the top of the view controller as var dataHelper: DataHelper
which sets the proiperty to the DataHelper class. The loading of that data can take up to five seconds to fully load, at this point. I was thinking I could use the the viewDidAppear method in the view controller to instantiate my data object after the screen appears and the tables would then be populated on screen rather than the beachball being displayed for those five seconds and the view being fully populated when it appears. However, I moved the instantiation of the data object (dataHelper = DataHelper()
) from viewDidLoad to the viewDidAppear method and the app still isn't displaying the screen until after the tables are populated. It introduced some other problems with my tableViews.
First, Is there something special to using this method? I have looked at tutorials on the web about view lifecycles and thought I understood how they work. I thought viewDidAppear meant the main app display was being actively displayed on the screen, but based on the five second blocking of the main thread that is not happening. I have also been using breakpoints and it appears the tableViews are running automatically before viewDidLoad() and viewDidAppear(). How do I not have the tableViews automatically load?
Here's the relevant code:
IBOutlet var mainTableView: NSTableView!
IBOutlet var secondTableView: NSTableView!
var dataHelper = DataHelper
override func viewDidAppear() {
super.viewDidAppear()
dataHelper = DataHelper()
dataHelper.loadData()
mainTableView.reloadData()
secondTableView.reloadData()
I wasn't expecting the tableView methods to be called until after the loadData method was called on my dataHelper object. It makes sense I guess, but how do I make the tables just appear as empty tables until the reloadData() methods are called? The third table is not a problem and it's okay to be populated when the view appears as the data is created at startup.
I will eventually look into seting up the data object instatiation as a secondary thread, but figured viewDidAppear would work for now just for my development purposes.