iOS 5 Wait for delegate to finish before populating a table?

别说谁变了你拦得住时间么 提交于 2019-12-24 10:16:32

问题


I am working on an iOS 5 app. I have a view controller that needs to display data as soon as its opened. The desired order of functionality is:

  1. Call a web service
  2. Wait for the reply from the web service (a delegate)
  3. Fill a data array
  4. Use the array to populate a list view
  5. Show the list view

I have all of the components in place but after the web service call is made, the program doesn't wait for a reply (asynchronous call) and instead fills the list view with blanks since the data array is not quite ready.

So I need help with either (1) making the program wait until the delegate finishes filling the array and then populating the list view or (2) re-initializing the listview after the delegate has completed and re-populating the whole list view. If I move the list view (like a scroll down) I see the desired data because the view is re-initialized. So I know that I have all the components in place, I just need to make them work in the desired order.


回答1:


If you mean "an UITableView instance" by list view, then let the web service finish loading, then refresh the table view:

- (void) myWebServiceDidFinishLoadingData
{
    [self.tableView reloadData];
}

Hope this helps.



来源:https://stackoverflow.com/questions/8898231/ios-5-wait-for-delegate-to-finish-before-populating-a-table

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