问题
I am using xCode 7 beta and swift, and storing my data using Parse.com. In which method in the UITableViewController should I be asking for data from my database? I need to ensure it is all present by the point in the lifecycle of the controller at which the cells need to be presented.
Is there anyway to guarantee this if I am loading data asynchronously?
回答1:
viewDidLoad
would be a good place for this but there might be a few second difference between displaying a blank tableView
and when it gets populated depending on how long it takes to pull your data.
So in viewDidLoad
you'll tell the Parse SDK to pull data and when it's complete, you can call [self.tableView reloadData]
回答2:
You should be asking for your data before the tableview is shown. That way you can pass your cells the ParseObject within the cellForIndexPath function. Then within your cell you can go ahead and get other information from ParseObject such as fetching relations or PFFIles etc
来源:https://stackoverflow.com/questions/31589467/loading-data-asynchronously-into-uitableview