Loading Data Asynchronously into UITableView

心不动则不痛 提交于 2021-02-20 04:24:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!